Java - ayuda con la interfaz grafica

 
Vista:

ayuda con la interfaz grafica

Publicado por Nicolas (1 intervención) el 12/09/2018 00:58:01
necesito ayuda no me funciona la interfaz ,no se que le falta o que error cometi





clase distanciapackage distancia;

import javax.swing.JOptionPane;

/**
*
* @author Usuario
*/
public class Distancia {public double metodo1 (double x1 ){
JOptionPane.showMessageDialog(null,"se calculo la distancia");

x1=Double.parseDouble(JOptionPane.showInputDialog("introduzca x2"));
return x1;
}
public double metodo2 ( double x2){
JOptionPane.showMessageDialog(null,"se calculo la distancia");

x2= Double.parseDouble(JOptionPane.showInputDialog("introdusca la primera coordenada x1"));
return x2;
}
public double metodo3 (double y1){

y1= Double.parseDouble(JOptionPane.showInputDialog("introduzca y1"));
return y1;
}
public double metodo4 (double y2){

y2= Double.parseDouble(JOptionPane.showInputDialog("introduzca y2"));
return y2;
}
public double metodoRes(double x1, double x2,double y1,double y2){
JOptionPane.showMessageDialog(null,"se calculo la distancia");
double res ;

res=Math.sqrt(Math.pow(x2-x1, 2)+Math.pow(x2-x1, 2));
JOptionPane.showMessageDialog(null,"la distancias es"+ res+ "unidades");
return res;
}


}





clase interfaz
import distancia.Distancia;

/*

* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/

/**
*
* @author Usuario
*/
public class interfaz extends javax.swing.JFrame {
private Distancia m ;


/**
* Creates new form interfaz
*/
public interfaz() {
m=new Distancia();
initComponents();
}

/**
* This method is called from within the constructor to initialize the form.
* WARNING: Do NOT modify this code. The content of this method is always
* regenerated by the Form Editor.
*/
@SuppressWarnings("unchecked")
// <editor-fold defaultstate="collapsed" desc="Generated Code">
private void initComponents() {

jLabel1 = new javax.swing.JLabel();
jLabel2 = new javax.swing.JLabel();
jLabel3 = new javax.swing.JLabel();
jLabel4 = new javax.swing.JLabel();
t1 = new javax.swing.JTextField();
t2 = new javax.swing.JTextField();
t3 = new javax.swing.JTextField();
t4 = new javax.swing.JTextField();
jButton1 = new javax.swing.JButton();

setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);

jLabel1.setText("x1");

jLabel2.setText("y1");

jLabel3.setText("x2");

jLabel4.setText("y2");

jButton1.setText("determinar distancia de los puntos");
jButton1.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jButton1ActionPerformed(evt);
}
});

javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
getContentPane().setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addGap(32, 32, 32)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(jLabel3)
.addGroup(layout.createSequentialGroup()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(jLabel1)
.addComponent(jLabel2)
.addComponent(jLabel4))
.addGap(30, 30, 30)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
.addComponent(t4, javax.swing.GroupLayout.DEFAULT_SIZE, 206, Short.MAX_VALUE)
.addComponent(t1, javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(t2, javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(t3, javax.swing.GroupLayout.Alignment.LEADING)))))
.addGroup(layout.createSequentialGroup()
.addGap(163, 163, 163)
.addComponent(jButton1, javax.swing.GroupLayout.PREFERRED_SIZE, 201, javax.swing.GroupLayout.PREFERRED_SIZE)))
.addContainerGap(323, Short.MAX_VALUE))
);
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addGap(50, 50, 50)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(jLabel1)
.addComponent(t1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
.addGap(51, 51, 51)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(jLabel2)
.addComponent(t2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
.addGap(34, 34, 34)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(jLabel3)
.addComponent(t3, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
.addGap(39, 39, 39)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(jLabel4)
.addComponent(t4, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 46, Short.MAX_VALUE)
.addComponent(jButton1)
.addContainerGap())
);

pack();
}// </editor-fold>

private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {
double a,b,c,d,dist;
a= m.metodo1((t1.getText()));
b= m.metodo2((t2.getText()));
c= m.metodo2((t3.getText()));
d= m.metodo2((t4.getText()));

dist=m.metodoRes(a, b, c, d);
// TODO add your handling code here:
}

/**
* @param args the command line arguments
*/
public static void main(String args[]) {
/* Set the Nimbus look and feel */
//<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
/* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
* For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html
*/
try {
for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
if ("Nimbus".equals(info.getName())) {
javax.swing.UIManager.setLookAndFeel(info.getClassName());
break;
}
}
} catch (ClassNotFoundException ex) {
java.util.logging.Logger.getLogger(interfaz.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (InstantiationException ex) {
java.util.logging.Logger.getLogger(interfaz.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (IllegalAccessException ex) {
java.util.logging.Logger.getLogger(interfaz.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (javax.swing.UnsupportedLookAndFeelException ex) {
java.util.logging.Logger.getLogger(interfaz.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
}
//</editor-fold>

/* Create and display the form */
java.awt.EventQueue.invokeLater(() -> {
new interfaz().setVisible(true);
});
}

// Variables declaration - do not modify
private javax.swing.JButton jButton1;
private javax.swing.JLabel jLabel1;
private javax.swing.JLabel jLabel2;
private javax.swing.JLabel jLabel3;
private javax.swing.JLabel jLabel4;
private javax.swing.JTextField t1;
private javax.swing.JTextField t2;
private javax.swing.JTextField t3;
private javax.swing.JTextField t4;
// End of variables declaration
}
Valora esta pregunta
Me gusta: Está pregunta es útil y esta claraNo me gusta: Está pregunta no esta clara o no es útil
0
Responder

ayuda con la interfaz grafica

Publicado por Mario (6 intervenciones) el 12/09/2018 16:34:12
El problema esta cuando se solicita los datos, hay que convertirlos a doubles

1
2
3
4
a = m.metodo1((Double.parseDouble(t1.getText())));
		b = m.metodo2((Double.parseDouble(t2.getText())));
		c = m.metodo2((Double.parseDouble(t3.getText())));
		d = m.metodo2((Double.parseDouble(t4.getText())));
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
0
Comentar
Imágen de perfil de Gustavo
Val: 5
Ha aumentado su posición en 4 puestos en Java (en relación al último mes)
Gráfica de Java

ayuda con la interfaz grafica

Publicado por Gustavo (3 intervenciones) el 17/09/2018 18:52:09
Porque no solo utilizas un Jframe que oriente tu programacion a objetos y no por clases que es mucho mas complicado?
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
0
Comentar