setTitle("Welcome to sum it up"); setLayout(null); setBounds(200, 100, 1200, 800); setVisible(true); setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); JPanel myTitle = new JPanel(); myTitle.add(new JLabel("Enter two operands,result and click on 'Check'")); JPanel myText = new JPanel(); myText.add(rValue); myText.add(new JLabel(" + ")); myText.add(lValue); myText.add(new JLabel(" = ")); myText.add(result); Box myMain = Box.createVerticalBox(); Component strut1 = Box.createVerticalStrut(5); Component strut2 = Box.createVerticalStrut(30); myMain.add(strut1); myMain.add(myTitle); myMain.add(myText); myMain.add(strut2); myMain.setBounds(360, 600, 300, 100); add(myMain); calcul.setBounds(450, 700, 100, 50); add(calcul);怎么改变myTitl
时间: 2024-03-22 14:36:54 浏览: 138
java学生通讯录实验报告.doc
e和myText的背景颜色?
要改变myTitle和myText的背景颜色,可以使用setBackground()方法。例如,要将myTitle的背景颜色设置为红色,可以在创建myTitle JPanel后调用myTitle.setBackground(Color.RED)。同样地,要将myText的背景颜色设置为绿色,可以在创建myText JPanel后调用myText.setBackground(Color.GREEN)。代码示例如下:
```
JPanel myTitle = new JPanel();
myTitle.setBackground(Color.RED);
myTitle.add(new JLabel("Enter two operands,result and click on 'Check'"));
JPanel myText = new JPanel();
myText.setBackground(Color.GREEN);
myText.add(rValue);
myText.add(new JLabel(" + "));
myText.add(lValue);
myText.add(new JLabel(" = "));
myText.add(result);
```
阅读全文