You ask some event triggers the question ~ ~

Category: Java SE
 
dengjiantao
2013-08-20 05:23:31

Sponsored Links
I write two forms, each in a different JAVA files, how to trigger the two by the time the form is connected. Example, click the first button on the form, the second form pops up, please advise Thank

Sponsored Links

ysss
2013-08-20 05:41:26
I do not know what you want to achieve the effect is not, the code is as follows
Form 1
import javax.swing. *;
import java. awt. *;
import java.awt.event. *;

public class test2 extends JFrame {
JPanel jPanel1 = ; new JPanel ();
JButton jButton1 = new JButton ();

public test2 () {
try {
jbInit ();
this . setSize (400,300);
this.show ();
}
; catch (Exception e) {
e.printStackTrace ();
}

}
public static void main (String [] args) {
test2 test21 = new test2 ();
}
private void jbInit () throws Exception {
jButton1.setText ("jButton1");
jButton1.addActionListener (new test2_jButton1_actionAdapter (this));
this.getContentPane (). add (jPanel1, BorderLayout.CENTER);
jPanel1.add (jButton1, null);
}

void jButton1_actionPerformed (ActionEvent e) {
new test3 ();
}

}

class test2_jButton1_actionAdapter implements java.awt.event.ActionListener {
test2 adaptee;

test2_jButton1_actionAdapter (test2 adaptee) {
this.adaptee = adaptee;
}
public void actionPerformed (ActionEvent e) {
adaptee.jButton1_actionPerformed (e);
}
}
alina520
2013-08-20 05:44:38
Form 2
import javax.swing.JFrame;

public class test3 extends JFrame {
public test3 ( ) {
this.setSize (200,100);
this.show ();
}
public static void main (String [] args) {
test3 test31 = new test3 () ;
}

}
xiaoyaoyixian123
2013-08-20 05:50:04
is event-triggered or time-triggered
lh200700303025
2013-08-20 05:55:57
If an event is triggered, then directly on your button bound to a listener on the line ah,
li176
2013-08-20 06:00:17
This I know, but how to make the pop-up window, the first two
Object obj = e.getSource ();
if (obj == button1)
{

}
playing parentheses statement how to write ~ ~
Domain and server ip had changed since 8/23/2013. Suspend the user registration and posts for program maintenance.