为什么编写的java界面,组件显示不出来,然后改变下窗口大小就显示出来了
importjavax.swing.*;importjava.awt.event.*;importjava.awt.*;publicclassDextendsJFrame...
import javax.swing.*;
import java.awt.event.*;import java.awt.*;
public class D extends JFrame implements WindowListener,ActionListener{
public D()
{
JButton b1=new JButton("开始游戏");
setTitle("欢迎来到黑白棋游戏!");
Container c=getContentPane();
c.setLayout(new BorderLayout());
JPanel j1=new JPanel();
JLabel a=new JLabel("用户名");
JLabel b=new JLabel("密码");
JTextField f=new JTextField(4);
JTextField f1=new JTextField(6);
addWindowListener(this);
JButton b2=new JButton("注册");
b2.addActionListener(this);
j1.setBackground(Color.blue);
JPanel j2=new JPanel();
JPanel j3=new JPanel();j3.setBackground(Color.blue);
j2.add(a);j2.add(f);j1.add(b2);
j3.add(b);j3.add(f1);
c.add(j2,BorderLayout.CENTER);
c.add(j3,BorderLayout.NORTH);
j1.add(b1);
b1.addActionListener(this);
c.add(j1,BorderLayout.SOUTH);
setSize(600,400);
}
public void windowClosing(WindowEvent e)
{System.exit(0);
}
public void windowClosed(WindowEvent e){}
public void windowActivated(WindowEvent e){}
public void windowDeactivated(WindowEvent e){}
public void windowOpened(WindowEvent e){}
public void windowIconified(WindowEvent e){}
public void windowDeiconified(WindowEvent e){}
public void actionPerformed(ActionEvent e)
{SD d=new SD();
d.setVisible(true);
dispose();}
public void paint(Graphics g)
{}
public static void main(String[] args) {
D d1=new D();
d1.setVisible(true);
// TODO Auto-generated method stub
}
} 展开
import java.awt.event.*;import java.awt.*;
public class D extends JFrame implements WindowListener,ActionListener{
public D()
{
JButton b1=new JButton("开始游戏");
setTitle("欢迎来到黑白棋游戏!");
Container c=getContentPane();
c.setLayout(new BorderLayout());
JPanel j1=new JPanel();
JLabel a=new JLabel("用户名");
JLabel b=new JLabel("密码");
JTextField f=new JTextField(4);
JTextField f1=new JTextField(6);
addWindowListener(this);
JButton b2=new JButton("注册");
b2.addActionListener(this);
j1.setBackground(Color.blue);
JPanel j2=new JPanel();
JPanel j3=new JPanel();j3.setBackground(Color.blue);
j2.add(a);j2.add(f);j1.add(b2);
j3.add(b);j3.add(f1);
c.add(j2,BorderLayout.CENTER);
c.add(j3,BorderLayout.NORTH);
j1.add(b1);
b1.addActionListener(this);
c.add(j1,BorderLayout.SOUTH);
setSize(600,400);
}
public void windowClosing(WindowEvent e)
{System.exit(0);
}
public void windowClosed(WindowEvent e){}
public void windowActivated(WindowEvent e){}
public void windowDeactivated(WindowEvent e){}
public void windowOpened(WindowEvent e){}
public void windowIconified(WindowEvent e){}
public void windowDeiconified(WindowEvent e){}
public void actionPerformed(ActionEvent e)
{SD d=new SD();
d.setVisible(true);
dispose();}
public void paint(Graphics g)
{}
public static void main(String[] args) {
D d1=new D();
d1.setVisible(true);
// TODO Auto-generated method stub
}
} 展开
2个回答
展开全部
import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
class Test extends JFrame {
JCheckBox checkbox;// 复选框
JComboBox combobox;// 下拉菜单
public Test() {
setSize(500, 500);
this.setLocation(300, 300);
setVisible(true);
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
checkbox = new JCheckBox("控制地区显示", true);
Container c = this.getContentPane();
c.setLayout(null);
c.add(checkbox);
checkbox.setLocation(100, 0);
checkbox.setSize(120, 20);
checkbox.addActionListener(new monitor());
combobox = new JComboBox();
c.add(combobox);
combobox.addItem("北京");
combobox.addItem("上海");
combobox.addItem("深圳");
combobox.addItem("平顶山");
combobox.setLocation(300, 0);
combobox.setSize(100, 20);
}
class monitor implements ActionListener {
public void actionPerformed(ActionEvent e) {
combobox.setEnabled(checkbox.isSelected());
}
}
public static void main(String args[]) {
Test e = new Test();
}
}
参考下我刚写的吧,,,
这是我写的玩,
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
class Test extends JFrame {
JCheckBox checkbox;// 复选框
JComboBox combobox;// 下拉菜单
public Test() {
setSize(500, 500);
this.setLocation(300, 300);
setVisible(true);
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
checkbox = new JCheckBox("控制地区显示", true);
Container c = this.getContentPane();
c.setLayout(null);
c.add(checkbox);
checkbox.setLocation(100, 0);
checkbox.setSize(120, 20);
checkbox.addActionListener(new monitor());
combobox = new JComboBox();
c.add(combobox);
combobox.addItem("北京");
combobox.addItem("上海");
combobox.addItem("深圳");
combobox.addItem("平顶山");
combobox.setLocation(300, 0);
combobox.setSize(100, 20);
}
class monitor implements ActionListener {
public void actionPerformed(ActionEvent e) {
combobox.setEnabled(checkbox.isSelected());
}
}
public static void main(String args[]) {
Test e = new Test();
}
}
参考下我刚写的吧,,,
这是我写的玩,
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询