62,623
社区成员
发帖
与我相关
我的任务
分享
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JButton;
import java.awt.Rectangle;
import javax.swing.JFrame;
class FrameB extends JFrame {
public FrameB() {
super("B窗体");
try {
jbInit();
this.setSize(200,200);
this.setLocation(100,100);
this.setVisible(true);
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
} catch (Exception ex) {
ex.printStackTrace();
}
}
private void jbInit() throws Exception {
this.setLayout(null);
jButton1.setBounds(new Rectangle(57, 106, 116, 42));
jButton1.setText("打开A窗口");
jButton1.addActionListener(new FrameB_jButton1_actionAdapter(this));
this.add(jButton1);
}
JButton jButton1 = new JButton();
public void jButton1_actionPerformed(ActionEvent e) {
FrameA a = new FrameA();
this.dispose();
}
}
class FrameB_jButton1_actionAdapter implements ActionListener {
private FrameB adaptee;
FrameB_jButton1_actionAdapter(FrameB adaptee) {
this.adaptee = adaptee;
}
public void actionPerformed(ActionEvent e) {
adaptee.jButton1_actionPerformed(e);
}
}
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JButton;
import javax.swing.JFrame;
import java.awt.Rectangle;
class FrameA extends JFrame {
public FrameA() {
super("A窗体");
try {
jbInit();
this.setSize(200,200);
this.setVisible(true);
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
} catch (Exception ex) {
ex.printStackTrace();
}
}
private void jbInit() throws Exception {
this.setLayout(null);
jButton1.setBounds(new Rectangle(57, 106, 112, 42));
jButton1.setText("打开B窗口");
jButton1.addActionListener(new FrameA_jButton1_actionAdapter(this));
this.add(jButton1);
}
JButton jButton1 = new JButton();
public void jButton1_actionPerformed(ActionEvent e) {
FrameB b = new FrameB();
this.dispose();
}
public static void main(String[] arg) {
new FrameA();
}
}
class FrameA_jButton1_actionAdapter implements ActionListener {
private FrameA adaptee;
FrameA_jButton1_actionAdapter(FrameA adaptee) {
this.adaptee = adaptee;
}
public void actionPerformed(ActionEvent e) {
adaptee.jButton1_actionPerformed(e);
}
}
import java.awt.Button;
import java.awt.FlowLayout;
import java.awt.Frame;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
class FrameA extends Frame {
private FrameA self = this;
public FrameA() {
setSize(40, 60);
setTitle("Ping命令");
setVisible(true);
setLayout(new FlowLayout());
setResizable(false);
addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent e) {
System.exit(0);
}
});
Button btn = new Button("打开FrameB");
btn.addActionListener(new ActionListener() {
public void actionPerformed(final ActionEvent evt) {
new FrameB(self);
self.setVisible(false);
}
});
add(btn);
validate();
}
}
class FrameB extends Frame {
private final FrameA frame;
public FrameB(FrameA framea) {
this.frame = framea;
setSize(400, 600);
this.setLocation(400, 0);
setVisible(true);
setLayout(new FlowLayout());
setResizable(false);
addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent e) {
System.exit(0);
}
});
Button btn = new Button("打开FrameA");
btn.addActionListener(new ActionListener() {
public void actionPerformed(final ActionEvent evt) {
frame.setVisible(true);
}
});
add(btn);
validate();
}
}
public class TestFrame extends Frame {
public static void main(String[] args) {
new FrameA();
}
}