JAVA图形界面问题 貌似是容器嵌套出问题??
编译无问题运行之后只有窗口各个组件都没显示出来里面是一片空白求修正importjavax.swing.*;importjava.awt.event.*;importjav...
编译无问题 运行之后 只有窗口
各个组件都没显示出来
里面是一片空白
求修正
import javax.swing.*;
import java.awt.event.*;
import java.awt.*;
class ChanPinChuKu extends JPanel {
JLabel number,name,amount,date,user,note,top;
JComboBox users;
JTextField number1,name1,amount1,date1,note1;
JPanel p1,p2;
JButton enter,cancle;
public void chanpin()
{
enter=new JButton("确定");
cancle=new JButton("取消");
p1=new JPanel();
p1.setLayout(new GridLayout(2,6));
p2=new JPanel();
p1.setBorder(BorderFactory.createTitledBorder("ok"));
top=new JLabel("请输入产品信息");
number=new JLabel("出库单号:");
name=new JLabel("产品名称:");
amount=new JLabel("数量:");
date=new JLabel("出库日期:");
user=new JLabel("操作员:");
note=new JLabel("备注:");
number.setHorizontalAlignment(JTextField.RIGHT);
name.setHorizontalAlignment(JTextField.RIGHT);
amount.setHorizontalAlignment(JTextField.RIGHT);
date.setHorizontalAlignment(JTextField.RIGHT);
user.setHorizontalAlignment(JTextField.RIGHT);
note.setHorizontalAlignment(JTextField.RIGHT);
number1=new JTextField(20);
amount1=new JTextField(20);
date1=new JTextField(20);
note1=new JTextField(20);
name1=new JTextField(20);
users=new JComboBox();
users.setSelectedIndex(0);
setLayout(new BorderLayout());
add(top,BorderLayout.NORTH);
add(p1,BorderLayout.CENTER);
add(p2,BorderLayout.SOUTH);
p1.add(number);p1.add(number1);p1.add(name);
p1.add(name1);p1.add(amount);p1.add(amount1);
p1.add(date);p1.add(date1);p1.add(user);
p1.add(users);p1.add(note);p1.add(note1);
p2.add(enter);p2.add(cancle);
}
public static void main(String[] args){
JFrame f=new JFrame();
ChanPinChuKu panel=new ChanPinChuKu();
f.add(panel);
f.setSize(800,700);
f.setVisible(true);
f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
} 展开
各个组件都没显示出来
里面是一片空白
求修正
import javax.swing.*;
import java.awt.event.*;
import java.awt.*;
class ChanPinChuKu extends JPanel {
JLabel number,name,amount,date,user,note,top;
JComboBox users;
JTextField number1,name1,amount1,date1,note1;
JPanel p1,p2;
JButton enter,cancle;
public void chanpin()
{
enter=new JButton("确定");
cancle=new JButton("取消");
p1=new JPanel();
p1.setLayout(new GridLayout(2,6));
p2=new JPanel();
p1.setBorder(BorderFactory.createTitledBorder("ok"));
top=new JLabel("请输入产品信息");
number=new JLabel("出库单号:");
name=new JLabel("产品名称:");
amount=new JLabel("数量:");
date=new JLabel("出库日期:");
user=new JLabel("操作员:");
note=new JLabel("备注:");
number.setHorizontalAlignment(JTextField.RIGHT);
name.setHorizontalAlignment(JTextField.RIGHT);
amount.setHorizontalAlignment(JTextField.RIGHT);
date.setHorizontalAlignment(JTextField.RIGHT);
user.setHorizontalAlignment(JTextField.RIGHT);
note.setHorizontalAlignment(JTextField.RIGHT);
number1=new JTextField(20);
amount1=new JTextField(20);
date1=new JTextField(20);
note1=new JTextField(20);
name1=new JTextField(20);
users=new JComboBox();
users.setSelectedIndex(0);
setLayout(new BorderLayout());
add(top,BorderLayout.NORTH);
add(p1,BorderLayout.CENTER);
add(p2,BorderLayout.SOUTH);
p1.add(number);p1.add(number1);p1.add(name);
p1.add(name1);p1.add(amount);p1.add(amount1);
p1.add(date);p1.add(date1);p1.add(user);
p1.add(users);p1.add(note);p1.add(note1);
p2.add(enter);p2.add(cancle);
}
public static void main(String[] args){
JFrame f=new JFrame();
ChanPinChuKu panel=new ChanPinChuKu();
f.add(panel);
f.setSize(800,700);
f.setVisible(true);
f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
} 展开
3个回答
展开全部
import java.awt.BorderLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.BorderFactory;
import javax.swing.JButton;
import javax.swing.JComboBox;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JTextField;
class ChanPinChuKu extends JPanel implements ActionListener{
JLabel number, name, amount, date, user, note, top;
JComboBox users;
JTextField number1, name1, amount1, date1, note1;
JPanel p1, p2;
JButton enter, cancle;
public ChanPinChuKu() {
enter = new JButton("确定");
cancle = new JButton("取消");
cancle.addActionListener(this);
enter.addActionListener(this);
p1 = new JPanel();
p1.setLayout(null);
p2 = new JPanel();
p1.setBorder(BorderFactory.createTitledBorder("ok"));
top = new JLabel("请输入产品信息");
number = new JLabel("出库单号:");
name = new JLabel("产品名称:");
amount = new JLabel("数量:");
date = new JLabel("出库日期:");
user = new JLabel("操作员:");
note = new JLabel("备注:");
number.setHorizontalAlignment(JTextField.RIGHT);
name.setHorizontalAlignment(JTextField.RIGHT);
amount.setHorizontalAlignment(JTextField.RIGHT);
date.setHorizontalAlignment(JTextField.RIGHT);
user.setHorizontalAlignment(JTextField.RIGHT);
note.setHorizontalAlignment(JTextField.RIGHT);
number1 = new JTextField(20);
amount1 = new JTextField(20);
date1 = new JTextField(20);
note1 = new JTextField(20);
name1 = new JTextField(20);
users = new JComboBox();
users.addItem("jack");
users.addItem("lucy");
users.addItem("jime");
users.setSelectedIndex(0);
setLayout(new BorderLayout());
add(top, BorderLayout.NORTH);
add(p1, BorderLayout.CENTER);
add(p2, BorderLayout.SOUTH);
number.setBounds(20,60,70,40);
p1.add(number);
number1.setBounds(100,67,90,25);
p1.add(number1);
name.setBounds(206,60,70,40);
p1.add(name);
name1.setBounds(288,67,90,25);
p1.add(name1);
amount.setBounds(365,60,70,40);
p1.add(amount);
amount1.setBounds(445,67,90,25);
p1.add(amount1);
date.setBounds(20,140,70,40);
p1.add(date);
date1.setBounds(100,147,90,25);
p1.add(date1);
user.setBounds(206,140,70,40);
p1.add(user);
users.setBounds(288,147,90,25);
p1.add(users);
note.setBounds(365,140,70,40);
p1.add(note);
note1.setBounds(445,147,90,25);
p1.add(note1);
p2.add(enter);
p2.add(cancle);
}
public static void main(String[] args) {
JFrame f = new JFrame("产品出库");
ChanPinChuKu panel = new ChanPinChuKu();
f.add(panel);
f.setBounds(400,100,580,350);
f.setVisible(true);
f.validate();
f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
@Override
public void actionPerformed(ActionEvent e) {
if(e.getSource()==cancle){
System.exit(1);
}else if(e.getSource()==enter){
JOptionPane.showMessageDialog(this, "保存成功!");
}
}
}
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.BorderFactory;
import javax.swing.JButton;
import javax.swing.JComboBox;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JTextField;
class ChanPinChuKu extends JPanel implements ActionListener{
JLabel number, name, amount, date, user, note, top;
JComboBox users;
JTextField number1, name1, amount1, date1, note1;
JPanel p1, p2;
JButton enter, cancle;
public ChanPinChuKu() {
enter = new JButton("确定");
cancle = new JButton("取消");
cancle.addActionListener(this);
enter.addActionListener(this);
p1 = new JPanel();
p1.setLayout(null);
p2 = new JPanel();
p1.setBorder(BorderFactory.createTitledBorder("ok"));
top = new JLabel("请输入产品信息");
number = new JLabel("出库单号:");
name = new JLabel("产品名称:");
amount = new JLabel("数量:");
date = new JLabel("出库日期:");
user = new JLabel("操作员:");
note = new JLabel("备注:");
number.setHorizontalAlignment(JTextField.RIGHT);
name.setHorizontalAlignment(JTextField.RIGHT);
amount.setHorizontalAlignment(JTextField.RIGHT);
date.setHorizontalAlignment(JTextField.RIGHT);
user.setHorizontalAlignment(JTextField.RIGHT);
note.setHorizontalAlignment(JTextField.RIGHT);
number1 = new JTextField(20);
amount1 = new JTextField(20);
date1 = new JTextField(20);
note1 = new JTextField(20);
name1 = new JTextField(20);
users = new JComboBox();
users.addItem("jack");
users.addItem("lucy");
users.addItem("jime");
users.setSelectedIndex(0);
setLayout(new BorderLayout());
add(top, BorderLayout.NORTH);
add(p1, BorderLayout.CENTER);
add(p2, BorderLayout.SOUTH);
number.setBounds(20,60,70,40);
p1.add(number);
number1.setBounds(100,67,90,25);
p1.add(number1);
name.setBounds(206,60,70,40);
p1.add(name);
name1.setBounds(288,67,90,25);
p1.add(name1);
amount.setBounds(365,60,70,40);
p1.add(amount);
amount1.setBounds(445,67,90,25);
p1.add(amount1);
date.setBounds(20,140,70,40);
p1.add(date);
date1.setBounds(100,147,90,25);
p1.add(date1);
user.setBounds(206,140,70,40);
p1.add(user);
users.setBounds(288,147,90,25);
p1.add(users);
note.setBounds(365,140,70,40);
p1.add(note);
note1.setBounds(445,147,90,25);
p1.add(note1);
p2.add(enter);
p2.add(cancle);
}
public static void main(String[] args) {
JFrame f = new JFrame("产品出库");
ChanPinChuKu panel = new ChanPinChuKu();
f.add(panel);
f.setBounds(400,100,580,350);
f.setVisible(true);
f.validate();
f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
@Override
public void actionPerformed(ActionEvent e) {
if(e.getSource()==cancle){
System.exit(1);
}else if(e.getSource()==enter){
JOptionPane.showMessageDialog(this, "保存成功!");
}
}
}
参考资料: 还有其他问题的话,给我发百度消息
展开全部
请在main函数中
ChanPinChuKu panel = new ChanPinChuKu();
下面加入一句
panel.chanpin();//初始化你的界面元素
另外这句语句users.setSelectedIndex(0);报错,请先注释掉再运行!
ChanPinChuKu panel = new ChanPinChuKu();
下面加入一句
panel.chanpin();//初始化你的界面元素
另外这句语句users.setSelectedIndex(0);报错,请先注释掉再运行!
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
把所有控件的visible属性设true;
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询