java点击按钮,出现另一个窗口
2016-11-24 20:25
573 查看
第一个窗体LoginFrame.java: package winRelation; import java.awt.Dimension; import java.awt.Rectangle; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import javax.swing.JButton; import javax.swing.JFrame; import javax.swing.JOptionPane; public class LoginFrame extends JFrame { JButton button = new JButton("点击我"); class LoginOKAction implements ActionListener { public void actionPerformed(ActionEvent e) { JOptionPane.showMessageDialog(null, "将进入另一个窗体!"); new MainFrame(); setVisible(false); } } public LoginFrame(){ super(); this.setResizable(false); this.setSize(new Dimension(300, 205)); this.setTitle("第一个窗体"); this.setLayout(null); this.setDefaultCloseOperation(EXIT_ON_CLOSE); this.setLocation(300, 200); this.setVisible(true); this.getContentPane().add(button, null); button.setBounds(new Rectangle(111, 70, 78, 27)); button.addActionListener(new LoginOKAction());//给按钮加事件监听器 } public static void main(String[] args) { new LoginFrame(); } } 第二个窗体MainFrame.java: package winRelation; import java.awt.BorderLayout; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import javax.swing.JButton; import javax.swing.JDesktopPane; import javax.swing.JFrame; import javax.swing.JInternalFrame; import javax.swing.JMenu; import javax.swing.JMenuBar; import javax.swing.JMenuItem; import javax.swing.JToolBar; public class MainFrame extends JFrame{ private static final JDesktopPane DESKTOP_PANE = new JDesktopPane(); public MainFrame() { super("这是主窗体"); setSize(640, 480); //菜单设置 JMenuBar menuBar = new JMenuBar(); this.setJMenuBar(menuBar); JMenu menu1 = new JMenu("菜单1"); JMenu menu101 = new JMenu("菜单101"); JMenuItem menu10101 = new JMenuItem("菜单10101"); JMenuItem menu102 = new JMenuItem("菜单102"); menu102.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { addIFame(new InternalFrame()); } }); menu101.add(menu10101); menu1.add(menu101); menu1.add(menu102); JMenu menu2 = new JMenu("菜单2"); menuBar.add(menu1); menuBar.add(menu2); this.getContentPane().add(DESKTOP_PANE); this.setVisible(true); } public static void addIFame(JInternalFrame iframe) { // 添加子窗体的方法 DESKTOP_PANE.add(iframe); } public static void main(String[] args) { new MainFrame(); } } 第三个窗体(MainFrame中的窗体)InternalFrame.java: package winRelation; import javax.swing.JButton; import javax.swing.JInternalFrame; public class InternalFrame extends JInternalFrame{ public InternalFrame() { super(); setClosable(true); setIconifiable(true); setTitle("内部窗体"); setBounds(50,50,400,300); setVisible(true); } }
相关文章推荐
- java在线聊天项目 swt可视化窗口Design 登录框注册按钮点击改变窗口大小——出现注册面板 实现打开登录框时屏幕居中
- 如何用java实现“点击一个按钮,出现另一个按钮”的功能?
- 在页面中,我们经常看到,一个button按钮,如果属标点击,就会触发一个窗口的显示,如果二次点击并可以隐藏,那么如何通过JAVA配合html来实现这一功能呢?
- JAVA 点击按钮后跳到另一个界面
- java点击按钮的时,打开另一个界面,原界面消失的方法
- Java点击按钮弹出窗口(两种按钮)
- Qt 主窗口点击按钮 弹出另一个自定义窗口
- Qt---- 点击按钮调用另一个窗口Ui
- 点击一个按钮,弹出框出现几秒钟之后,跳转到另一个页面
- C#中点击按钮出现多个子窗口该怎么解决?
- Java中实现用户点击关闭窗口按钮后提示用户,选择“是”后退到父窗口,选择“否”留在原窗口
- 从一个窗口获取另一个窗口点击的按钮
- 按钮点击后UIview淡出,并出现另一个按钮的方法
- 点击按钮出现新窗口
- java swing中点击按钮后弹出JFrame窗口,关闭弹出的窗口,程序都关了的解决方案
- 点击按钮时弹出另一个能控制大小的页面,并将某些值通过POST方式传给这个弹出的窗口
- [AHK]监控某些窗口出现时点击某些按钮
- Javascript判断是否点击了页面窗口的关闭按钮
- 如何点击按钮弹出新窗口,输入数据后返回并刷新页面?
- 在ASP.NET中,点击按钮弹出新窗口