📄 frame1.java
字号:
package ex09_08;import java.awt.*;import java.awt.event.*;import javax.swing.*;import javax.swing.border.*;public class Frame1 extends JFrame { JPanel contentPane; ButtonGroup buttonGroup1 = new ButtonGroup(); JLabel jLabel1 = new JLabel(); JCheckBox jCheckBox1 = new JCheckBox(); JCheckBox jCheckBox2 = new JCheckBox(); JCheckBox jCheckBox3 = new JCheckBox(); JPanel jPanel1 = new JPanel(); TitledBorder titledBorder1; JTextField jTextField1 = new JTextField(); JTextField jTextField2 = new JTextField(); JTextField jTextField3 = new JTextField(); JLabel jLabel2 = new JLabel(); JButton jButton1 = new JButton(); JPanel jPanel2 = new JPanel(); TitledBorder titledBorder2; JRadioButton jRadioButton1 = new JRadioButton(); JRadioButton jRadioButton2 = new JRadioButton(); JLabel jLabel3 = new JLabel(); JLabel jLabel4 = new JLabel(); JLabel jLabel5 = new JLabel(); /**Construct the frame*/ public Frame1() { enableEvents(AWTEvent.WINDOW_EVENT_MASK); try { jbInit(); } catch(Exception e) { e.printStackTrace(); } } /**Component initialization*/ private void jbInit() throws Exception { //setIconImage(Toolkit.getDefaultToolkit().createImage(Frame1.class.getResource("[Your Icon]"))); contentPane = (JPanel) this.getContentPane(); titledBorder1 = new TitledBorder(""); titledBorder2 = new TitledBorder(""); jLabel1.setText("“酷”泡沫红茶店Menu"); jLabel1.setBounds(new Rectangle(58, 12, 161, 19)); contentPane.setLayout(null); this.setSize(new Dimension(400, 300)); this.setTitle("Frame Title"); jCheckBox1.setText("泡沫红茶(35元)"); jCheckBox1.setBounds(new Rectangle(6, 4, 114, 27)); jCheckBox2.setText("菊花茶(50元)"); jCheckBox2.setBounds(new Rectangle(5, 34, 90, 27)); jCheckBox3.setText("木瓜奶茶(40元)"); jCheckBox3.setBounds(new Rectangle(6, 61, 114, 27)); jPanel1.setBorder(titledBorder1); jPanel1.setBounds(new Rectangle(32, 43, 212, 96)); jPanel1.setLayout(null); jTextField1.setText("0"); jTextField1.setBounds(new Rectangle(121, 12, 63, 23)); jTextField2.setText("0"); jTextField2.setBounds(new Rectangle(121, 37, 63, 23)); jTextField3.setText("0"); jTextField3.setBounds(new Rectangle(121, 62, 63, 23)); jLabel2.setBorder(BorderFactory.createLoweredBevelBorder()); jLabel2.setBounds(new Rectangle(146, 145, 89, 32)); jButton1.setText("结帐"); jButton1.setBounds(new Rectangle(154, 186, 79, 29)); jButton1.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(ActionEvent e) { jButton1_actionPerformed(e); } }); jPanel2.setBorder(titledBorder2); jPanel2.setBounds(new Rectangle(25, 147, 104, 72)); jPanel2.setLayout(null); jRadioButton1.setSelected(true); jRadioButton1.setText("内用"); jRadioButton1.setBounds(new Rectangle(15, 12, 51, 27)); jRadioButton2.setText("外带"); jRadioButton2.setBounds(new Rectangle(14, 35, 56, 27)); jLabel3.setText("杯"); jLabel3.setBounds(new Rectangle(187, 43, 41, 19)); jLabel4.setBounds(new Rectangle(189, 15, 41, 19)); jLabel4.setText("杯"); jLabel5.setText("杯"); jLabel5.setBounds(new Rectangle(188, 66, 41, 19)); contentPane.add(jLabel1, null); contentPane.add(jPanel1, null); jPanel1.add(jCheckBox1, null); jPanel1.add(jCheckBox3, null); jPanel1.add(jCheckBox2, null); jPanel1.add(jTextField3, null); jPanel1.add(jTextField2, null); jPanel1.add(jTextField1, null); jPanel1.add(jLabel5, null); jPanel1.add(jLabel3, null); jPanel1.add(jLabel4, null); contentPane.add(jPanel2, null); jPanel2.add(jRadioButton2, null); jPanel2.add(jRadioButton1, null); contentPane.add(jLabel2, null); contentPane.add(jButton1, null); buttonGroup1.add(jRadioButton2); buttonGroup1.add(jRadioButton1); } /**Overridden so we can exit when window is closed*/ protected void processWindowEvent(WindowEvent e) { super.processWindowEvent(e); if (e.getID() == WindowEvent.WINDOW_CLOSING) { System.exit(0); } } void jButton1_actionPerformed(ActionEvent e) {int money=0;//泡沫红茶if (jCheckBox1.isSelected()) { money=money+(35*(Integer.parseInt(jTextField1.getText()))); }//菊花茶if (jCheckBox2.isSelected()) { money=money+(50*(Integer.parseInt(jTextField2.getText()))); }//木瓜奶茶if (jCheckBox3.isSelected()) { money=money+(40*(Integer.parseInt(jTextField3.getText()))); } //外带还是内用 if (jRadioButton2.isSelected()) money=money+0; //外带不加钱 else money=money+100; //内用收服务费100元 //显示总金额 jLabel2.setText("$"+String.valueOf(money)); }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -