Comment Appeler JFrame à partir d'une autre classe Java

Je suis en train de faire un simple Jform et l'appeler à partir d'une autre classe.
Je veux utiliser cette Jframe dans un serveur d'application client, mais je ne sais pas comment ouvrir la JFrame classe d'une autre classe.

Comme l'utilisateur a choisi

1 - pour ouvrir Jframe.

2 - À La Sortie.

Donc Ce que je fais mal?

Ci-dessous les codes:

Jframe Classe nommée Calculas.java

/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
/**
*
* @author user
*/
public class Calculas extends javax.swing.JFrame {
/**
* Creates new form Calculas
*/
public Calculas() {
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() {
a1Text = new javax.swing.JTextField();
a2Text = new javax.swing.JTextField();
jLabel1 = new javax.swing.JLabel();
jButton1 = new javax.swing.JButton();
answer = new javax.swing.JLabel();
setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
jButton1.setText("jButton1");
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()
.addContainerGap()
.addComponent(a1Text, javax.swing.GroupLayout.PREFERRED_SIZE, 43, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
.addComponent(a2Text, javax.swing.GroupLayout.PREFERRED_SIZE, 97, javax.swing.GroupLayout.PREFERRED_SIZE)
.addGap(87, 87, 87)
.addComponent(answer, javax.swing.GroupLayout.PREFERRED_SIZE, 67, javax.swing.GroupLayout.PREFERRED_SIZE))
.addGroup(layout.createSequentialGroup()
.addGap(113, 113, 113)
.addComponent(jLabel1))
.addGroup(layout.createSequentialGroup()
.addContainerGap()
.addComponent(jButton1)))
.addContainerGap(86, Short.MAX_VALUE))
);
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addGap(19, 19, 19)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(a1Text, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(a2Text, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
.addComponent(answer, javax.swing.GroupLayout.PREFERRED_SIZE, 24, javax.swing.GroupLayout.PREFERRED_SIZE))
.addGap(60, 60, 60)
.addComponent(jLabel1)
.addGap(34, 34, 34)
.addComponent(jButton1)
.addContainerGap(140, Short.MAX_VALUE))
);
pack();
}//</editor-fold>                        
private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {                                         
int a;
a = Integer.parseInt(a1Text.getText()) + Integer.parseInt(a2Text.getText());
answer.setText("Answer" + a);
//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(Calculas.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (InstantiationException ex) {
java.util.logging.Logger.getLogger(Calculas.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (IllegalAccessException ex) {
java.util.logging.Logger.getLogger(Calculas.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (javax.swing.UnsupportedLookAndFeelException ex) {
java.util.logging.Logger.getLogger(Calculas.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
}
//</editor-fold>
/* Create and display the form */
java.awt.EventQueue.invokeLater(new Runnable() {
public void run() {
new Calculas().setVisible(true);
}
});
}
//Variables declaration - do not modify                     
private javax.swing.JTextField a1Text;
private javax.swing.JTextField a2Text;
private javax.swing.JLabel answer;
private javax.swing.JButton jButton1;
private javax.swing.JLabel jLabel1;
//End of variables declaration                   
}

De la Classe de Test nommé Test.java

public class Test extends JFrame {
public static void main(String args[])
{
Calculas CAL = new Calculas();
CAL.Calculus();
}
}
Il suffit d'exécuter le calculas classe. Il a déjà une méthode main.
Que faire si l'OP veut inclure la Calculas classe dans une autre classe et les besoins de la référence à la Calculas classe pour les autres choses, comme le paramètre/l'obtention de propriétés? L'Appel De Calculas.principal directement ne va pas atteindre ce - juste dire
Ok, got it =). @JonathanLopez Vous pouvez simplement copier/coller de la méthode main en dessous de la ligne de Calculas CAL = new Calculas(); et modifier la ligne new Calculas().setVisible(true); à CAL.setVisible(true); de la Calculas classe (pour être en mesure d'avoir le Nimbus look).
Voir L'Utilisation de Plusieurs JFrames, Bonne/Mauvaise Pratique?
vient demande va...ne revient jamais....

OriginalL'auteur Jonathan Lopez | 2013-06-10