1个回答
展开全部
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JButton;
import javax.swing.JFrame;
public class FrameTest extends JFrame {
private static final long serialVersionUID = 1L;
private int lx = 200;
private int ly = 200;
public FrameTest(){
}
public FrameTest(int x , int y) {
this.lx = x;
this.ly = y;
this.setBounds(lx, ly, 400, 300);
}
public void init(){
this.setBounds(lx, ly, 400, 300);
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
this.setLayout(null);
JButton bton = new JButton("EXIT");
JButton bnew = new JButton("NEW");
bton.setBounds(80, 80, 80, 50);
bnew.setBounds(180, 80, 80, 50);
bnew.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e) {
new FrameTest(200, 400).init();
}
});
bton.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e) {
System.exit(0);
}
});
this.add(bton);
this.add(bnew);
this.setVisible(true);
}
public static void main(String[] args) {
new FrameTest().init();
}
}
import java.awt.event.ActionListener;
import javax.swing.JButton;
import javax.swing.JFrame;
public class FrameTest extends JFrame {
private static final long serialVersionUID = 1L;
private int lx = 200;
private int ly = 200;
public FrameTest(){
}
public FrameTest(int x , int y) {
this.lx = x;
this.ly = y;
this.setBounds(lx, ly, 400, 300);
}
public void init(){
this.setBounds(lx, ly, 400, 300);
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
this.setLayout(null);
JButton bton = new JButton("EXIT");
JButton bnew = new JButton("NEW");
bton.setBounds(80, 80, 80, 50);
bnew.setBounds(180, 80, 80, 50);
bnew.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e) {
new FrameTest(200, 400).init();
}
});
bton.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e) {
System.exit(0);
}
});
this.add(bton);
this.add(bnew);
this.setVisible(true);
}
public static void main(String[] args) {
new FrameTest().init();
}
}
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询