📄 loginframe.java
字号:
package cartinterface;import java.awt.*;import java.awt.event.*;import javax.swing.*;import data.*;public class LoginFrame extends JFrame implements ActionListener { JPanel contentPane; JLabel jLabel1 = new JLabel(); JTextField jTextField1 = new JTextField(); JButton jButton1 = new JButton(); JButton jButton2 = new JButton(); //创建字体类 Font dialog13 = new java.awt.Font("Dialog", 0, 13); public LoginFrame() { try { jbInit(); } catch(Exception e) { e.printStackTrace(); } } private void jbInit() throws Exception { contentPane = (JPanel) this.getContentPane(); contentPane.setLayout(null); this.setSize(new Dimension(400, 300)); this.setTitle("购物车登陆窗口"); jLabel1.setText("顾客名字:"); jLabel1.setBounds(new Rectangle(72, 79, 79, 29)); jLabel1.setFont(dialog13); jTextField1.setBounds(new Rectangle(193, 83, 141, 22)); jTextField1.setFont(dialog13); jButton1.setText("商品浏览窗口"); jButton1.setActionCommand("cartApp"); jButton1.setBounds(new Rectangle(72, 161, 127, 25)); jButton1.setFont(dialog13); jButton1.addActionListener(this); jButton2.setText("退出"); jButton2.setActionCommand("exit"); jButton2.setBounds(new Rectangle(207, 161, 127, 25)); jButton2.setFont(dialog13); jButton2.addActionListener(this); contentPane.add(jButton2, null); contentPane.add(jButton1, null); contentPane.add(jTextField1, null); contentPane.add(jLabel1, null); } protected void processWindowEvent(WindowEvent e) { if (e.getID() == WindowEvent.WINDOW_CLOSING) { System.exit(0); } } //按钮单击事件 public void actionPerformed(ActionEvent e) { //取得按钮的动作字符串 String actionCommand = e.getActionCommand().trim(); //单击按钮的处理代码 if (actionCommand.equals("cartApp")) { //取得顾客的名字 String name = jTextField1.getText(); if(name.trim().length() == 0){ JOptionPane.showMessageDialog(null, "请输入顾客的名字"); return; } //创建购物车类 Cart cart = new Cart(); //设置顾客的名字 cart.setCustomer(name); //创建窗口类 CartFrame frame = new CartFrame(cart); Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize(); Dimension frameSize = frame.getSize(); if (frameSize.height > screenSize.height) { frameSize.height = screenSize.height; } if (frameSize.width > screenSize.width) { frameSize.width = screenSize.width; } //使窗口居中对齐 frame.setLocation((screenSize.width - frameSize.width) / 2, (screenSize.height - frameSize.height) / 2); frame.setVisible(true); }else if(actionCommand.equals("exit")){ System.exit(0); } }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -