【发布时间】:2015-11-28 16:15:34
【问题描述】:
在这段代码中,前三个按钮出现在文本区域,我怎样才能让这些按钮从标题下方开始?在添加按钮之前,按钮区域从标题下方开始,但是一旦我添加了按钮,它就会出现在标题上
public Design ()
{
header = new JPanel ();
header.setBounds(0, 0, 300, 100);
header.setBackground(Color.WHITE);
header.setLayout (null);
buttonarea = new JPanel ();
buttonarea.setBounds (0,0, 300, 300);
buttonarea.setBackground(Color.BLACK);
buttonarea.setLayout(new GridLayout (6,3));
add (header);
add (buttonarea);
zero = new JButton ("0");
zero.setBackground(Color.PINK);
one = new JButton ("1");
one.setBackground(Color.PINK);
two = new JButton ("2");
two.setBackground(Color.PINK);
three = new JButton ("3");
three.setBackground(Color.PINK);
four = new JButton ("4");
four.setBackground(Color.PINK);
five = new JButton ("5");
five.setBackground(Color.PINK);
six = new JButton ("6");
six.setBackground(Color.PINK);
seven = new JButton ("7");
seven.setBackground(Color.PINK);
eight = new JButton ("8");
eight.setBackground(Color.PINK);
nine = new JButton ("9");
nine.setBackground(Color.PINK);
add = new JButton ("+");
add.setBackground(Color.PINK);
subtract = new JButton ("-");
subtract.setBackground(Color.PINK);
divide = new JButton ("*");
divide.setBackground(Color.PINK);
multiply = new JButton ("/");
multiply.setBackground(Color.PINK);
square = new JButton ("x^2");
square.setBackground(Color.PINK);
equal = new JButton ("=");
equal.setBackground(Color.PINK);
c = new JButton ("C");
c.setBackground(Color.PINK);
clear = new JButton ("delete");
clear.setBackground(Color.PINK);
dot = new JButton (".");
dot.setBackground(Color.PINK);
written = new JTextArea ();
written.setBackground(Color.WHITE);
header.add (written);
buttonarea.add (c);
buttonarea.add (clear);
buttonarea.add (equal);
buttonarea.add (zero);
buttonarea.add (one);
buttonarea.add (add);
buttonarea.add (two);
buttonarea.add (three);
buttonarea.add (subtract);
buttonarea.add (four);
buttonarea.add (five);
buttonarea.add (multiply);
buttonarea.add (six);
buttonarea.add (seven);
buttonarea.add (square);
buttonarea.add (eight);
buttonarea.add (nine);
buttonarea.add (dot);
}
【问题讨论】:
标签: java swing calculator