2个回答
2013-07-25
展开全部
import java.awt.BorderLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JButton;
import javax.swing.JFrame;
public class ButtonJFrame extends JFrame {
ButtonJFrame() {
super("ButtonJFrame");
JButton btnA = new JButton("打开FrameA");
JButton btnB = new JButton("打开FrameB");
this.setLayout(new BorderLayout());
this.getContentPane().add(btnA, BorderLayout.WEST);
this.getContentPane().add(btnB, BorderLayout.EAST);
btnA.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
new FrameA().setVisible(true);
}
});
btnB.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
new FrameB().setVisible(true);
}
});
this.setSize(320, 240);
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
this.setVisible(true);
}
public static void main(String[] args) {
new ButtonJFrame();
}
class FrameA extends JFrame {
FrameA() {
super("FrameA");
this.setSize(160, 120);
}
}
class FrameB extends JFrame {
FrameB() {
super("FrameB");
this.setSize(160, 120);
}
}
}
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JButton;
import javax.swing.JFrame;
public class ButtonJFrame extends JFrame {
ButtonJFrame() {
super("ButtonJFrame");
JButton btnA = new JButton("打开FrameA");
JButton btnB = new JButton("打开FrameB");
this.setLayout(new BorderLayout());
this.getContentPane().add(btnA, BorderLayout.WEST);
this.getContentPane().add(btnB, BorderLayout.EAST);
btnA.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
new FrameA().setVisible(true);
}
});
btnB.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
new FrameB().setVisible(true);
}
});
this.setSize(320, 240);
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
this.setVisible(true);
}
public static void main(String[] args) {
new ButtonJFrame();
}
class FrameA extends JFrame {
FrameA() {
super("FrameA");
this.setSize(160, 120);
}
}
class FrameB extends JFrame {
FrameB() {
super("FrameB");
this.setSize(160, 120);
}
}
}
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
设计两个JPanel 或JFrame 点不同按钮打开不同界面不行吗?
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询
广告 您可能关注的内容 |