当前位置: 技术问答>java相关
窗口的简单问题~~~
来源: 互联网 发布时间:2015-06-18
本文导语: 我建立2个窗体,一个是主窗口,副窗口通过点击主窗口按扭弹出。主窗体有2个按扭,其中一个放入显示副窗体代码,能够显示,但第二个就不行,很奇怪,代码如下: //可以显示 void jButton1_actionPerformed(ActionEven...
我建立2个窗体,一个是主窗口,副窗口通过点击主窗口按扭弹出。主窗体有2个按扭,其中一个放入显示副窗体代码,能够显示,但第二个就不行,很奇怪,代码如下:
//可以显示
void jButton1_actionPerformed(ActionEvent e) {
if (!proxy.start) {
jButton1.setText("停止代理");
//jButton1.setEnabled(false);
proxy.start=true;
System.out.println("准备启动代理服务器");
JFrame frame2=new Frame2();
frame2.show();
//frame2.setVisible(true);
}
else {
proxy.start=false;
jButton1.setText("启动代理");
System.out.println("已经停止代理服务器");
}
}
//不能显示
void jButton2_actionPerformed(ActionEvent e) {
JFrame frame2=new Frame2();
//frame2.show();
frame2.setVisible(true);
}
问题继续:第一个按扭能显示副窗体,但只是标题栏大小,我设了“窗口大小位置”和“窗口大小可变”参数,但仍然不能改变副窗口的大小,应该如何设置呀?部分代码:
class Frame2 extends JFrame {
JLabel jLabel1 = new JLabel();
static JTextField user_count = new JTextField();
JButton jButton1 = new JButton();
JButton jButton2 = new JButton();
JButton jButton3 = new JButton();
JTextField jTextField2 = new JTextField();
List List1 = new List();
JLabel jLabel2 = new JLabel();
Border border1;
public Frame2() {
try {
jbInit();
}
catch(Exception e) {
e.printStackTrace();
}
}
private void jbInit() throws Exception {
border1 = new EtchedBorder(EtchedBorder.RAISED,Color.white,new Color(134, 134, 134));
jLabel1.setFont(new java.awt.Font("Dialog", 0, 14));
jLabel1.setToolTipText("");
jLabel1.setText("用户数量:");
jLabel1.setBounds(new Rectangle(14, 17, 74, 36));
this.setSize(new Dimension(238, 315));
this.setTitle("代理服务器-设置");
this.getContentPane().setLayout(null);
user_count.setToolTipText("");
user_count.setText("10");
user_count.setBounds(new Rectangle(93, 17, 61, 32));
jButton1.setBounds(new Rectangle(167, 91, 67, 36));
jButton1.setBorder(BorderFactory.createEtchedBorder());
jButton1.setToolTipText("");
jButton1.setText("添加");
//jButton1.setEnabled(false);
jButton1.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(ActionEvent e) {
jButton1_actionPerformed(e);
}
});
jButton2.setBounds(new Rectangle(167, 144, 67, 36));
jButton2.setBorder(BorderFactory.createEtchedBorder());
jButton2.setToolTipText("");
jButton2.setText("删除");
jButton2.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(ActionEvent e) {
jButton2_actionPerformed(e);
}
});
jButton3.setBounds(new Rectangle(167, 14, 67, 36));
jButton3.setBorder(BorderFactory.createEtchedBorder());
jButton3.setText("确认");
jButton3.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(ActionEvent e) {
jButton3_actionPerformed(e);
}
});
jTextField2.setFont(new java.awt.Font("SansSerif", 0, 14));
jTextField2.setBounds(new Rectangle(9, 93, 145, 31));
list1.setFont(new java.awt.Font("Dialog", 0, 14));
list1.setBounds(new Rectangle(9, 142, 145, 153));
jLabel2.setFont(new java.awt.Font("Dialog", 0, 14));
jLabel2.setToolTipText("");
jLabel2.setText("过滤站点:");
jLabel2.setBounds(new Rectangle(14, 57, 72, 30));
this.setResizable(false);
this.getContentPane().add(jLabel2, null);
this.getContentPane().add(jLabel1, null);
this.getContentPane().add(user_count, null);
this.getContentPane().add(jTextField2, null);
this.getContentPane().add(list1, null);
this.getContentPane().add(jButton2, null);
this.getContentPane().add(jButton1, null);
this.getContentPane().add(jButton3, null);
}
//可以显示
void jButton1_actionPerformed(ActionEvent e) {
if (!proxy.start) {
jButton1.setText("停止代理");
//jButton1.setEnabled(false);
proxy.start=true;
System.out.println("准备启动代理服务器");
JFrame frame2=new Frame2();
frame2.show();
//frame2.setVisible(true);
}
else {
proxy.start=false;
jButton1.setText("启动代理");
System.out.println("已经停止代理服务器");
}
}
//不能显示
void jButton2_actionPerformed(ActionEvent e) {
JFrame frame2=new Frame2();
//frame2.show();
frame2.setVisible(true);
}
问题继续:第一个按扭能显示副窗体,但只是标题栏大小,我设了“窗口大小位置”和“窗口大小可变”参数,但仍然不能改变副窗口的大小,应该如何设置呀?部分代码:
class Frame2 extends JFrame {
JLabel jLabel1 = new JLabel();
static JTextField user_count = new JTextField();
JButton jButton1 = new JButton();
JButton jButton2 = new JButton();
JButton jButton3 = new JButton();
JTextField jTextField2 = new JTextField();
List List1 = new List();
JLabel jLabel2 = new JLabel();
Border border1;
public Frame2() {
try {
jbInit();
}
catch(Exception e) {
e.printStackTrace();
}
}
private void jbInit() throws Exception {
border1 = new EtchedBorder(EtchedBorder.RAISED,Color.white,new Color(134, 134, 134));
jLabel1.setFont(new java.awt.Font("Dialog", 0, 14));
jLabel1.setToolTipText("");
jLabel1.setText("用户数量:");
jLabel1.setBounds(new Rectangle(14, 17, 74, 36));
this.setSize(new Dimension(238, 315));
this.setTitle("代理服务器-设置");
this.getContentPane().setLayout(null);
user_count.setToolTipText("");
user_count.setText("10");
user_count.setBounds(new Rectangle(93, 17, 61, 32));
jButton1.setBounds(new Rectangle(167, 91, 67, 36));
jButton1.setBorder(BorderFactory.createEtchedBorder());
jButton1.setToolTipText("");
jButton1.setText("添加");
//jButton1.setEnabled(false);
jButton1.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(ActionEvent e) {
jButton1_actionPerformed(e);
}
});
jButton2.setBounds(new Rectangle(167, 144, 67, 36));
jButton2.setBorder(BorderFactory.createEtchedBorder());
jButton2.setToolTipText("");
jButton2.setText("删除");
jButton2.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(ActionEvent e) {
jButton2_actionPerformed(e);
}
});
jButton3.setBounds(new Rectangle(167, 14, 67, 36));
jButton3.setBorder(BorderFactory.createEtchedBorder());
jButton3.setText("确认");
jButton3.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(ActionEvent e) {
jButton3_actionPerformed(e);
}
});
jTextField2.setFont(new java.awt.Font("SansSerif", 0, 14));
jTextField2.setBounds(new Rectangle(9, 93, 145, 31));
list1.setFont(new java.awt.Font("Dialog", 0, 14));
list1.setBounds(new Rectangle(9, 142, 145, 153));
jLabel2.setFont(new java.awt.Font("Dialog", 0, 14));
jLabel2.setToolTipText("");
jLabel2.setText("过滤站点:");
jLabel2.setBounds(new Rectangle(14, 57, 72, 30));
this.setResizable(false);
this.getContentPane().add(jLabel2, null);
this.getContentPane().add(jLabel1, null);
this.getContentPane().add(user_count, null);
this.getContentPane().add(jTextField2, null);
this.getContentPane().add(list1, null);
this.getContentPane().add(jButton2, null);
this.getContentPane().add(jButton1, null);
this.getContentPane().add(jButton3, null);
}
|
第一个问题:jButton2按钮不能显示Frame2,这个问题很奇怪,我试过,肯定可以。也许你觉得它没有显示,是因为你开头已经显示了一个Frame2且没有关闭,所以刷新上看来没有任何变化
第二个问题:你可以在Frame2的
try {
//此处添加
this.setSize(400,300);//设定长度400,宽度300
jbInit();
}
即可
第二个问题:你可以在Frame2的
try {
//此处添加
this.setSize(400,300);//设定长度400,宽度300
jbInit();
}
即可
您可能感兴趣的文章:
本站(WWW.)旨在分享和传播互联网科技相关的资讯和技术,将尽最大努力为读者提供更好的信息聚合和浏览方式。
本站(WWW.)站内文章除注明原创外,均为转载、整理或搜集自网络。欢迎任何形式的转载,转载请注明出处。
本站(WWW.)站内文章除注明原创外,均为转载、整理或搜集自网络。欢迎任何形式的转载,转载请注明出处。