弹出窗口问题(拜托个位高人了,急!!!) 使用监听事件,有两个界面A和B,当单击A中的一个按扭时,弹出界面B,切界面A不见,那个监听事件怎么写? 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 package com.ddpie.frame;import java.awt.FlowLayout;import java.awt.event.ActionEvent;import java.awt.event.ActionListener;import javax.swing.JButton;import javax.swing.JFrame;public class TestFrameSwitch { public static void main(String[] args) { final JFrame frameA = new JFrame("窗口A"); final JFrame frameB = new JFrame("窗口B"); JButton buttonA = new JButton("切换成窗口B"); JButton buttonB = new JButton("切换成窗口A"); frameA.getContentPane().setLayout(new FlowLayout(FlowLayout.CENTER,0,0)); frameB.getContentPane().setLayout(new FlowLayout(FlowLayout.CENTER,0,0)); frameA.getContentPane().add(buttonA); frameB.getContentPane().add(buttonB); frameA.setSize(300, 200); frameB.setSize(600, 600); frameA.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frameB.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frameA.setVisible(true); buttonA.addActionListener(new ActionListener(){ public void actionPerformed(ActionEvent e) { frameA.setVisible(false); frameB.setVisible(true); } }); buttonB.addActionListener(new ActionListener(){ public void actionPerformed(ActionEvent e) { frameB.setVisible(false); frameA.setVisible(true); } }); }} 如果是两个panel切换可以考虑用CardLayout 对于这种情况 建议写两个单独的Frame类 不要写在一个类中 添加功能时会很乱 也难后期修改 一般来说,一个Frame就应该是一个类 真心求教java怎么播放url地址的MP3. 使用泛型能提高效率吗? 读字符串 GUI编程中,数据库驱动加载不了,请问是怎么回事?? 如何使用java class的反射功能 想学习排序算法 这个错误如何解决呢 关于图片显示的问题,100分 WEB里响应onClick事件的函数是否可以用JAVA写,而不用JSCRIP写??? 请教两个入门问题 致JAVA初学者+如何下手学JAVA [精华] 关于SWT的,请懂的大虾教教小弟
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;import javax.swing.JButton;
import javax.swing.JFrame;public class TestFrameSwitch {
public static void main(String[] args) {
final JFrame frameA = new JFrame("窗口A");
final JFrame frameB = new JFrame("窗口B");
JButton buttonA = new JButton("切换成窗口B");
JButton buttonB = new JButton("切换成窗口A");
frameA.getContentPane().setLayout(new FlowLayout(FlowLayout.CENTER,0,0));
frameB.getContentPane().setLayout(new FlowLayout(FlowLayout.CENTER,0,0));
frameA.getContentPane().add(buttonA);
frameB.getContentPane().add(buttonB);
frameA.setSize(300, 200);
frameB.setSize(600, 600);
frameA.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frameB.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frameA.setVisible(true);
buttonA.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e) {
frameA.setVisible(false);
frameB.setVisible(true);
}
});
buttonB.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e) {
frameB.setVisible(false);
frameA.setVisible(true);
}
});
}}