一个视窗设计的很菜的问题。

flyprogram 2004-06-13 01:31:13
小弟开始学JAVA的视窗设计,遇到一个问题,由于现实在没人可问,所以只能上来请大家指导指导。问题是,共有两个JPanel,运行一个jPanel1后,按下一个按钮后如何弹出另个一个JPanel呢,以下是程序的全部代码,事件部分是空的(注释的的那两行),请高手帮忙填一下,不尽感激。(情况就类似于,运行一个程序,在程序界面上有一个按钮,叫“配置程序的参数”,按下去后弹出一个面板,可以进行参数的配置,完了按确定返回。)
package test;
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
class test extends JFrame{
JPanel jPanel1 = new JPanel();
JPanel jPanel2 = new JPanel();
JLabel jLabel1 = new JLabel();
JLabel jLabel2 = new JLabel();
JButton jButton1 = new JButton();
JButton jButton2 = new JButton();
BorderLayout borderLayout1 = new BorderLayout();
BorderLayout borderLayout2 = new BorderLayout();

public test() {
try {
jbInit();
}
catch(Exception e) {
e.printStackTrace();
}
}
private void jbInit() throws Exception {
jPanel1=(JPanel)this.getContentPane();
jLabel1.setText("this is panel1");
jLabel2.setText("this is panel2 ");
jButton1.setText("确定并返回panel1");
jPanel2.setLayout(borderLayout2);
jPanel1.setLayout(borderLayout1);
jButton2.setToolTipText("");
jButton2.setText("运行panel2设置程序运行参数");
jButton2.addActionListener(new test_jButton2_actionAdapter(this));
jPanel2.add(jLabel2, BorderLayout.SOUTH);
jPanel2.add(jButton1, BorderLayout.SOUTH);
jPanel1.add(jButton2, BorderLayout.SOUTH);
jPanel1.add(jLabel1, BorderLayout.NORTH);
jButton1.addActionListener(new test_jButton1_actionAdapter(this));
}
public static void main(String []args){
test t1=new test();
t1.setSize(new Dimension (300,400));
t1.setVisible(true);

}

void jButton2_actionPerformed(ActionEvent e) {
//运行panel2,进行系统参数的设置,并且panel1不可操作(就是鼠标点不到panel1了),只能由panel返回后才能继续操作
/*下面是我自己以为的代码,是错误的
jPanel2=(JPanel)this.getContentPane();
jPanel2.setSize(new Dimension (300, 400));
jPanel2.setVisible(true);*/

}

void jButton1_actionPerformed(ActionEvent e) {
//设置完毕,返回panel1
}
}

class test_jButton2_actionAdapter implements java.awt.event.ActionListener {
test adaptee;

test_jButton2_actionAdapter(test adaptee) {
this.adaptee = adaptee;
}
public void actionPerformed(ActionEvent e) {
adaptee.jButton2_actionPerformed(e);
}
}

class test_jButton1_actionAdapter implements java.awt.event.ActionListener {
test adaptee;

test_jButton1_actionAdapter(test adaptee) {
this.adaptee = adaptee;
}
public void actionPerformed(ActionEvent e) {
adaptee.jButton1_actionPerformed(e);
}
}


...全文
148 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
MAX°孟兆 2004-06-14
  • 打赏
  • 举报
回复
为不么不用JTabbedPane呢.
RomandAccessFile 2004-06-14
  • 打赏
  • 举报
回复
前面用 dispose();就看不见了,如果要让后来的焦点聚在后来的窗口上,
可以将后边的这个类extends JDialog,然后将前者的Frame传给后者,这样,就可以了,
楼上的方法也是可以的,
lixiang823517 2004-06-14
  • 打赏
  • 举报
回复
前面的dispose();就看不见了

焦点用setFoucos什么什么的,昨天看球没睡觉,晕的,清醒了再来~
flyprogram 2004-06-14
  • 打赏
  • 举报
回复
有什么区别?你能不能简单说一下?
flyprogram 2004-06-13
  • 打赏
  • 举报
回复
不会吧,一个都没有回?。。。

62,623

社区成员

发帖
与我相关
我的任务
社区描述
Java 2 Standard Edition
社区管理员
  • Java SE
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧