关于swing中窗口? 有3个类,窗口类A中有一个按钮,能开启窗口类B且关闭窗口A!如何实现? 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 Frame a = ...;button x = ...x.addActionListener(new ActionListener() { public void actionPerformed(Event event) { YourWindow b = new JFrame(.., a); b.setVisible(true); // or b.pack(); } });class YourWindow extends JFrame { private Button a; public YourWindow(..., Button a) { ...; this.a = a; } void someMethod() { a.setVisible(false); //or a.dispose(); }} YourWindow 中的a应改为JFrame 在A的按钮事件中先让A关闭(AFrame.this.dispose()或AFrame.this.SetVisible(false)),再让B可见(BFrame.setVisible(true))。 import javax.swing.*;import java.awt.*;import java.awt.event.*;class FrameA extends JFrame implements ActionListener{ JButton button; FrameA(String s){ super(s); button = new JButton("Open another window"); button.setSize(80, 60); this.setBounds(100, 100, 400, 300); Container mainPane = this.getContentPane(); mainPane.add(button, BorderLayout.NORTH); this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); this.setVisible(true); button.addActionListener(this); } public void actionPerformed(ActionEvent e){ JFrame frameB = new JFrame("Frame B"); frameB.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frameB.setBounds(200,200, 200, 160); frameB.setVisible(true); this.dispose(); }}public class ThreeFrame { public static void main(String[] args){ FrameA frameA = new FrameA("Frame A"); }} 我定义了一个抽象类,模板函数,在子类中实现模板函数,为什么没有响应? TOMCAT 解压WAR包 只能解析成 tldCache.ser?? java大量文件如何处理? 这样的服务器开发,mina? Java中,tree的节点,能否显示两个图标? 对编程特感兴趣,但是目前是外行,请教几个问题!!! 一道面试题 JList问题求教! 求个时间算法。 大家看看这段简单的关于文件操作的例子!有个错误,不知道如何该! 一个要简单又不简单的问题,望大家来看看!!!! 高手请进,虚心求教中。。。
button x = ...
x.addActionListener(new ActionListener() {
public void actionPerformed(Event event) {
YourWindow b = new JFrame(.., a);
b.setVisible(true); // or b.pack();
}
});
class YourWindow extends JFrame {
private Button a;
public YourWindow(..., Button a) {
...;
this.a = a;
}
void someMethod() {
a.setVisible(false); //or a.dispose();
}
}
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;class FrameA extends JFrame implements ActionListener{
JButton button;
FrameA(String s){
super(s);
button = new JButton("Open another window");
button.setSize(80, 60);
this.setBounds(100, 100, 400, 300);
Container mainPane = this.getContentPane();
mainPane.add(button, BorderLayout.NORTH);
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
this.setVisible(true);
button.addActionListener(this);
}
public void actionPerformed(ActionEvent e){
JFrame frameB = new JFrame("Frame B");
frameB.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frameB.setBounds(200,200, 200, 160);
frameB.setVisible(true);
this.dispose();
}
}
public class ThreeFrame { public static void main(String[] args){ FrameA frameA = new FrameA("Frame A");
}
}