急!!!Java菜鸟 GUI方面的问题

来源:百度知道 编辑:UC知道 时间:2024/06/18 16:39:02
import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.*;
public class CompanyGUI extends JFrame
{
private Container contentPanel;
private JPanel northPanel;
private JPanel centerPanel;
private JButton messageButton;
private JButton roomselectButton;
private JButton equipmentselectButton;
private JButton equipmentlistButton;
private JButton cancelButton;
private JButton orderedButton;
private JButton waitingButton;
private JButton exitButton;

CompanyGUI()
{
super("会议室预定系统");
contentPanel=this.getContentPane();
//contentPanel.setLayout(new BorderLayout());
northPanel=new JPanel();
centerPanel=new JPanel(new BorderLayout());
messag

centerPanel.add(new JLabel("sssssssssssss"));
不能这样动态去添加一个组件,在这里你确实已经监听到了messageButton,而且也将lable加入到centerPanel中了,但是效果看不出来,你需要将centerPanel重绘才能看到,添加不等于显示。

很简单

centerPanel.add(new JLabel("sssssssssssss"));

后面加上

centerPanel.updateUI();


ActionListener a1 = new ActionListener() {
public void actionPerformed(ActionEvent e) {
centerPanel.add(new JLabel("sssssssssssss"));
centerPanel.updateUI();
}
};