0
我有点卡住了。我应该显示2个按钮和1个标签,但我的程序没有显示它们。如果你有任何想法,这将是伟大的。我正在使用eclipse,代码正在编译和运行。这是代码。不显示按钮和标签
/** This is the driver class of the program.
* Here is the main method with the JFrame.
* class name RunFurniture.class
* @author Kiril Anastasov
* @date 18/03/2012
*/
import java.awt.*;
import javax.swing.*;
public class RunRurniture
{
/**
* @param args
*/
public static void main(String[] args)
{
JFrame application = new JFrame();
PanelFurniture panel = new PanelFurniture();
application.add(panel);
application.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
application.setSize(600,450);
application.setLocationByPlatform(true);
application.setVisible(true);
}
}
/** Here is the GUI of the program.
* class name PanelFurniture.class
* @author Kiril Anastasov
* @date 18/03/2012
*/
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.*;
public class PanelFurniture extends JPanel implements ActionListener
{
JLabel label;
JButton a,b;
JPanel centerPanel, eastPanel;
public void actionPerformed(ActionEvent ae)
{
this.setLayout(new BorderLayout());
centerPanel = new JPanel();
//centerPanel.setLayout();
this.add(centerPanel, BorderLayout.CENTER);
eastPanel = new JPanel(new GridLayout(1,3));
label = new JLabel();
b = new JButton("Move");
eastPanel.add(b);
eastPanel.add(label);
a = new JButton("ee");
eastPanel.add(a);
//this.add(eastPanel);
this.add(eastPanel, BorderLayout.EAST);
}
}
ooo我现在看到,我觉得很愚蠢,因为我看不到我的问题。队友的欢呼声! – Kiril 2012-03-18 08:53:17
我可以问一下,将jlabel/jbuttons放入数组或图像中是否是一种好的做法 – Kiril 2012-03-18 09:04:05
当你有很多这样的东西,并且需要经历所有这些东西时,这是一个很好的练习:)它让事情变得更简单。 – MByD 2012-03-18 09:05:15