📄 mainwindow.java
字号:
package com.lovo.testminibook.view;
import java.awt.Color;
import java.awt.ComponentOrientation;
import java.awt.Dimension;
import java.awt.Font;
import java.awt.Image;
import java.awt.Point;
import java.awt.Rectangle;
import java.awt.Toolkit;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.KeyEvent;
import java.util.Vector;
import javax.swing.BorderFactory;
import javax.swing.ButtonGroup;
import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JComboBox;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JRadioButton;
import javax.swing.JScrollPane;
import javax.swing.JTable;
import javax.swing.JTextField;
import javax.swing.ListSelectionModel;
import javax.swing.SwingConstants;
import javax.swing.table.DefaultTableModel;
import com.lovo.testminibook.control.AddLinkMan;
import com.lovo.testminibook.control.DelLinkMan;
import com.lovo.testminibook.control.SearchLinkMan;
import com.lovo.testminibook.control.SelectLinkMan;
import com.lovo.testminibook.control.UpdateLinkMan;
import com.lovo.testminibook.util.FileUtil;
public class MainWindow extends JFrame {
private static final long serialVersionUID = 1L;
private JTextField addressjTextField4 = null;
private JTextField agejTextField1 = null;
private ButtonGroup bg=new ButtonGroup();
private JButton jButton = null;
private JButton jButton1 = null;
private JButton jButton2 = null;
private JButton jButton3 = null;
private JButton jButton4 = null;
private JComboBox jComboBox = null;
private JPanel jContentPane = null;
private JLabel jLabel = null;
private JLabel jLabel1 = null;
private JLabel jLabel2 = null;
private JLabel jLabel21 = null;
private JLabel jLabel22 = null;
private JLabel jLabel23 = null;
private JLabel jLabel24 = null;
private JLabel jLabel25 = null;
private JLabel jLabel3 = null;
private JLabel jLabel4 = null;
private JLabel jLabel5 = null;
private JPanel jPanel = null;
private JRadioButton jRadioButton = null;
private JRadioButton jRadioButton1 = null;
private JTable jTable1 = null;
private JTextField jTextField5 = null;
private JTextField namejTextField2 = null;
private JTextField numberjTextField = null;
private JTextField phonejTextField3 = null;
/**
* This is the default constructor
*/
public MainWindow() {
super();
initialize();
}
/**
* This method initializes addressjTextField4
*
* @return javax.swing.JTextField
*/
public JTextField getAddressjTextField4() {
if (addressjTextField4 == null) {
addressjTextField4 = new JTextField();
addressjTextField4.setBounds(new Rectangle(86, 363, 120, 20));
}
return addressjTextField4;
}
/**
* This method initializes agejTextField1
*
* @return javax.swing.JTextField
*/
public JTextField getAgejTextField1() {
if (agejTextField1 == null) {
agejTextField1 = new JTextField();
agejTextField1.setBounds(new Rectangle(86, 311, 80, 20));
}
return agejTextField1;
}
/**
* This method initializes jButton
*
* @return javax.swing.JButton
*/
private JButton getJButton() {
if (jButton == null) {
jButton = new JButton();
jButton.setMnemonic(KeyEvent.VK_UNDEFINED);
jButton.setComponentOrientation(ComponentOrientation.LEFT_TO_RIGHT);
jButton.setHorizontalAlignment(SwingConstants.LEFT);
jButton.setHorizontalTextPosition(SwingConstants.TRAILING);
jButton.setPreferredSize(new Dimension(45, 77));
jButton.setSize(new Dimension(93, 28));
jButton.setLocation(new Point(58, 77));
jButton.setBackground(new Color(238, 238, 238));
jButton.setFont(new Font("Dialog", Font.BOLD, 12));
jButton.setText("查询");
jButton.setBackground(Color.white);
jButton.setBorderPainted(false);
ImageIcon icon = new ImageIcon("img/024.png");
Image image = icon.getImage().getScaledInstance(20, 20, 0);
icon.setImage(image);
jButton.setIcon(icon);
jButton.addActionListener(new SearchLinkMan(this));
}
return jButton;
}
/**
* This method initializes jButton1
*
* @return javax.swing.JButton
*/
private JButton getJButton1() {
if (jButton1 == null) {
jButton1 = new JButton();
jButton1.setBounds(new Rectangle(158, 410, 90, 32));
jButton1.setHorizontalAlignment(SwingConstants.LEFT);
jButton1.setText("添加");
jButton1.setBorderPainted(false);
jButton1.setBackground(Color.white);
jButton1.setIcon(new ImageIcon("img/014.png"));
jButton1.addActionListener(new AddLinkMan(this));
}
return jButton1;
}
/**
* This method initializes jButton2
*
* @return javax.swing.JButton
*/
private JButton getJButton2() {
if (jButton2 == null) {
jButton2 = new JButton();
jButton2.setBounds(new Rectangle(251, 410, 90, 32));
jButton2.setText("删除");
jButton2.setBorderPainted(false);
jButton2.setBackground(Color.white);
jButton2.setIcon(new ImageIcon("img/017.png"));
jButton2.addActionListener(new DelLinkMan(this));
}
return jButton2;
}
/**
* This method initializes jButton3
*
* @return javax.swing.JButton
*/
private JButton getJButton3() {
if (jButton3 == null) {
jButton3 = new JButton();
jButton3.setBounds(new Rectangle(346, 410, 90, 32));
jButton3.setText("修改");
jButton3.setBorderPainted(false);
jButton3.setBackground(Color.white);
jButton3.setIcon(new ImageIcon("img/070.png"));
jButton3.addActionListener(new UpdateLinkMan(this));
}
return jButton3;
}
/**
* This method initializes jButton4
*
* @return javax.swing.JButton
*/
private JButton getJButton4() {
if (jButton4 == null) {
jButton4 = new JButton();
jButton4.setBounds(new Rectangle(440, 410, 90, 32));
jButton4.setText("退出");
jButton4.setBorderPainted(false);
jButton4.setBackground(Color.white);
jButton4.setIcon(new ImageIcon("img/030.png"));
jButton4.addActionListener(new ActionListener(){
@Override
public void actionPerformed(ActionEvent e) {
JOptionPane.showMessageDialog(null, "谢谢使用");
System.exit(0);
}
});
}
return jButton4;
}
/**
* This method initializes jComboBox
*
* @return javax.swing.JComboBox
*/
public JComboBox getJComboBox() {
if (jComboBox == null) {
String str[]={"按学号查询","按姓名查询","全部查询"};
jComboBox = new JComboBox(str);
jComboBox.setBounds(new Rectangle(81, 23, 107, 20));
jComboBox.setBackground(Color.white);
}
return jComboBox;
}
/**
* This method initializes jContentPane
*
* @return javax.swing.JPanel
*/
private JPanel getJContentPane() {
if (jContentPane == null) {
jLabel3 = new JLabel();
jLabel3.setBounds(new Rectangle(442, 272, 30, 20));
jLabel3.setText("查询");
jLabel25 = new JLabel();
jLabel25.setBounds(new Rectangle(48, 363, 31, 20));
jLabel25.setText("地址");
jLabel24 = new JLabel();
jLabel24.setBounds(new Rectangle(48, 337, 31, 20));
jLabel24.setText("性别");
jLabel23 = new JLabel();
jLabel23.setBounds(new Rectangle(175, 311, 31, 20));
jLabel23.setText("电话");
jLabel22 = new JLabel();
jLabel22.setBounds(new Rectangle(48, 311, 31, 20));
jLabel22.setText("年龄");
jLabel21 = new JLabel();
jLabel21.setBounds(new Rectangle(175, 286, 31, 20));
jLabel21.setText("姓名");
jLabel2 = new JLabel();
jLabel2.setBounds(new Rectangle(48, 286, 31, 20));
jLabel2.setText("学号");
jLabel1 = new JLabel();
jLabel1.setBounds(new Rectangle(312, 17, 80, 39));
jLabel1.setFont(new Font("Dialog", Font.BOLD, 24));
jLabel1.setText("通讯录");
jLabel = new JLabel();
jLabel.setBounds(new Rectangle(275, 16, 37, 38));
jLabel.setIcon(new ImageIcon("img/007.png"));
jLabel.setPreferredSize(new Dimension(0, 0));
jLabel.setText("");
jContentPane = new JPanel();
jContentPane.setLayout(null);
jContentPane.setBackground(Color.white);
jContentPane.add(jLabel, null);
jContentPane.add(jLabel1, null);
jContentPane.add(jLabel2, null);
jContentPane.add(jLabel21, null);
jContentPane.add(jLabel22, null);
jContentPane.add(jLabel23, null);
jContentPane.add(jLabel24, null);
jContentPane.add(jLabel25, null);
jContentPane.add(getNumberjTextField(), null);
jContentPane.add(getAgejTextField1(), null);
jContentPane.add(getNamejTextField2(), null);
jContentPane.add(getJRadioButton(), null);
jContentPane.add(getJRadioButton1(), null);
jContentPane.add(getPhonejTextField3(), null);
jContentPane.add(getAddressjTextField4(), null);
jContentPane.add(jLabel3, null);
jContentPane.add(getJPanel(), null);
jContentPane.add(getJButton1(), null);
jContentPane.add(getJButton2(), null);
jContentPane.add(getJButton3(), null);
jContentPane.add(getJButton4(), null);
JScrollPane jsp=new JScrollPane(getJTable1());
jsp.setBounds(10, 59, 677, 205);
jContentPane.add(jsp, null);
}
return jContentPane;
}
/**
* This method initializes jPanel
*
* @return javax.swing.JPanel
*/
private JPanel getJPanel() {
if (jPanel == null) {
jLabel5 = new JLabel();
jLabel5.setBounds(new Rectangle(17, 51, 57, 20));
jLabel5.setText("查询值");
jLabel4 = new JLabel();
jLabel4.setBounds(new Rectangle(17, 23, 57, 20));
jLabel4.setText("查询字段");
jPanel = new JPanel();
jPanel.setLayout(null);
jPanel.setBounds(new Rectangle(431, 281, 210, 115));
jPanel.setBorder(BorderFactory.createLineBorder(Color.cyan, 1));
jPanel.setBackground(Color.white);
jPanel.add(jLabel4, null);
jPanel.add(jLabel5, null);
jPanel.add(getJComboBox(), null);
jPanel.add(getJTextField5(), null);
jPanel.add(getJButton(), null);
}
return jPanel;
}
/**
* This method initializes jRadioButton
*
* @return javax.swing.JRadioButton
*/
public JRadioButton getJRadioButton() {
if (jRadioButton == null) {
jRadioButton = new JRadioButton();
jRadioButton.setBounds(new Rectangle(87, 337, 40, 20));
jRadioButton.setBackground(Color.white);
jRadioButton.setText("男");
jRadioButton.setSelected(true);
bg.add(jRadioButton);
}
return jRadioButton;
}
/**
* This method initializes jRadioButton1
*
* @return javax.swing.JRadioButton
*/
public JRadioButton getJRadioButton1() {
if (jRadioButton1 == null) {
jRadioButton1 = new JRadioButton();
jRadioButton1.setBounds(new Rectangle(126, 337, 40, 20));
jRadioButton1.setBackground(Color.white);
jRadioButton1.setText("女");
bg.add(jRadioButton1);
}
return jRadioButton1;
}
/**
* This method initializes jTable1
*
* @return javax.swing.JTable
*/
public JTable getJTable1() {
if (jTable1 == null) {
jTable1 = new JTable();
jTable1.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
jTable1.addMouseListener(new SelectLinkMan(this));
this.setJTable();
}
return jTable1;
}
/**
* This method initializes jTextField5
*
* @return javax.swing.JTextField
*/
public JTextField getJTextField5() {
if (jTextField5 == null) {
jTextField5 = new JTextField();
jTextField5.setBounds(new Rectangle(81, 51, 107, 20));
}
return jTextField5;
}
/**
* This method initializes namejTextField2
*
* @return javax.swing.JTextField
*/
public JTextField getNamejTextField2() {
if (namejTextField2 == null) {
namejTextField2 = new JTextField();
namejTextField2.setBounds(new Rectangle(212, 286, 80, 20));
}
return namejTextField2;
}
/**
* This method initializes numberjTextField
*
* @return javax.swing.JTextField
*/
public JTextField getNumberjTextField() {
if (numberjTextField == null) {
numberjTextField = new JTextField();
numberjTextField.setBounds(new Rectangle(86, 286, 80, 20));
}
return numberjTextField;
}
/**
* This method initializes phonejTextField3
*
* @return javax.swing.JTextField
*/
public JTextField getPhonejTextField3() {
if (phonejTextField3 == null) {
phonejTextField3 = new JTextField();
phonejTextField3.setBounds(new Rectangle(212, 311, 80, 20));
}
return phonejTextField3;
}
/**
* This method initializes this
*
* @return void
*/
private void initialize() {
this.setIconImage(Toolkit.getDefaultToolkit().getImage("img/005.png"));
this.setResizable(false);
this.setBounds(new Rectangle(100, 100, 710, 500));
this.setContentPane(getJContentPane());
this.setTitle("通讯录");
this.setVisible(true);
}
/**
* This method initializes jTable
*
* @return javax.swing.JTable
*/
public void reset(){
this.getNumberjTextField().setText("");
this.getAgejTextField1().setText("");
this.getNamejTextField2().setText("");
this.getPhonejTextField3().setText("");
this.getAddressjTextField4().setText("");
}
public void setJTable(){
FileUtil fu = new FileUtil();
DefaultTableModel dtm=new DefaultTableModel(fu.getDateVector(), fu.getHeadVector());
jTable1.setModel(dtm);
}
public void setJTable(Vector dateVector,Vector HeadVector){
FileUtil fu = new FileUtil();
DefaultTableModel dtm=new DefaultTableModel(dateVector,HeadVector);
jTable1.setModel(dtm);
}
public static void main(String[]args){
new MainWindow();
}
} // @jve:decl-index=0:visual-constraint="10,-28"
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -