📄 addframe.java
字号:
package bus;import javax.swing.*;import java.awt.*;import java.awt.event.*;//import com.borland.jbcl.layout.*;import javax.swing.border.*;import java.beans.*;import java.util.*;public class AddFrame extends JFrame { JTabbedPane TabPanel = new JTabbedPane(); JPanel pe_table = new JPanel(); JPanel pe_button = new JPanel(); JButton bt_save = new JButton(); JButton bt_del = new JButton(); Border border1; GridBagLayout gridBagLayout1 = new GridBagLayout(); JLabel la1 = new JLabel(); JComboBox box1 = new JComboBox(); JLabel la2 = new JLabel(); JTextField tf_time = new JTextField(); JLabel la3 = new JLabel(); JTextField tf_money = new JTextField(); BusManager bm=new BusManager(); public AddFrame() { this.setSize(300,300); try { jbInit(); } catch(Exception e) { e.printStackTrace(); } } private void jbInit() throws Exception { border1 = BorderFactory.createEmptyBorder(); bt_save.setFont(new java.awt.Font("Dialog", 0, 12)); bt_save.setPreferredSize(new Dimension(60, 25)); bt_save.setText("保存"); bt_del.setFont(new java.awt.Font("Dialog", 0, 12)); bt_del.setPreferredSize(new Dimension(60, 25)); bt_del.setText("取消"); pe_table.setEnabled(true); pe_table.setFont(new java.awt.Font("Dialog", 0, 16)); pe_table.setAlignmentY((float) 0.5); pe_table.setDebugGraphicsOptions(0); pe_table.setMinimumSize(new Dimension(0, 0)); pe_table.setRequestFocusEnabled(true); pe_table.setToolTipText("车票收入信息"); pe_table.setVerifyInputWhenFocusTarget(true); pe_table.setLayout(gridBagLayout1); la1.setFont(new java.awt.Font("Dialog", 0, 16)); la1.setText("车牌号:"); la2.setFont(new java.awt.Font("Dialog", 0, 16)); la2.setText("出车时间:"); tf_time.setPreferredSize(new Dimension(100, 22)); tf_time.setText(""); la3.setFont(new java.awt.Font("Dialog", 0, 16)); la3.setText("收入金额:"); tf_money.setPreferredSize(new Dimension(100, 22)); tf_money.setText(""); box1.setPreferredSize(new Dimension(100, 22)); TabPanel.setToolTipText(""); this.getContentPane().add(TabPanel, BorderLayout.CENTER); TabPanel.add(pe_table, "车票收入信息"); this.getContentPane().add(pe_button, BorderLayout.SOUTH); pe_button.add(bt_save, null); pe_button.add(bt_del, null); pe_table.add(la2, new GridBagConstraints(0, 1, 1, 1, 0.0, 0.0 ,GridBagConstraints.CENTER, GridBagConstraints.NONE, new Insets(0, 0, 0, 0), 0, 9)); pe_table.add(tf_time, new GridBagConstraints(1, 1, 1, 1, 0.0, 0.0 ,GridBagConstraints.CENTER, GridBagConstraints.NONE, new Insets(0, 0, 0, 0), 13, 5)); pe_table.add(la3, new GridBagConstraints(0, 2, 1, 2, 0.0, 0.0 ,GridBagConstraints.CENTER, GridBagConstraints.NONE, new Insets(0, 0, 0, 0), 0, 11)); pe_table.add(tf_money, new GridBagConstraints(1, 2, 1, 2, 0.0, 0.0 ,GridBagConstraints.CENTER, GridBagConstraints.NONE, new Insets(0, 0, 0, 0), 12, 5)); pe_table.add(la1, new GridBagConstraints(0, 0, 1, 1, 0.0, 0.0 ,GridBagConstraints.SOUTHWEST, GridBagConstraints.NONE, new Insets(0, 6, 0, 21), 0, 10)); pe_table.add(box1, new GridBagConstraints(1, 0, 1, 1, 0.0, 0.0 ,GridBagConstraints.SOUTHEAST, GridBagConstraints.NONE, new Insets(0, 28, 0, 26), 14, 5)); bt_del.addActionListener(new AL()); this.setTitle("车票收入信息"); double w=Toolkit.getDefaultToolkit().getScreenSize().getWidth(); double h=Toolkit.getDefaultToolkit().getScreenSize().getHeight(); int x=(int)(this.getWidth())/2; int y=(int)(this.getHeight())/2; this.setLocation(x,y); this.setVisible(true); Vector no=new Vector(); no=bm.selectBus("select BusPai from BusGuanli"); for(int i=0;i<no.size();i++) { Vector vt=new Vector(); vt=(Vector)no.get(i); box1.addItem(vt.get(0)); } TabPanel.setSelectedComponent(pe_table); bt_save.addActionListener(new AL()); } class AL implements ActionListener{ public void actionPerformed(ActionEvent e){ if(e.getSource()==bt_del){ AddFrame.this.dispose(); } if(e.getSource()==bt_save){ Object bus=box1.getSelectedItem().toString(); String tim=tf_time.getText(); String mon=tf_money.getText(); String s="insert into PiaoRu (BusPai,InTime,InLiang) values('"+bus+"','"+tim+"',"+mon+")"; bm.updateBus(s); System.out.println(s); System.out.println("更新成功"); if(tim.equals("")){ JOptionPane.showMessageDialog(null,"出车时间不能为空"); } if(mon.equals("")) { JOptionPane.showMessageDialog(null,"金额不能为空"); } } } }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -