📄 primarykey.java
字号:
package catking.home.love;
import java.sql.*;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public abstract class PrimaryKey extends JFrame implements ActionListener{
protected JTextField tf;
private final String[] buttonNames = {"确定","清除","退出"};
public PrimaryKey(String title,String info)
{
super(title);
this.setSize(600,450);
Container c = this.getContentPane();
this.setLayout(new GridLayout(3,1,0,0));
c.add(new JLabel(""));
JPanel panel = new JPanel();
panel.setLayout(new GridLayout(3,1,0,5));
JLabel infoLabel = new JLabel(info,SwingConstants.CENTER);
tf = new JTextField(30);
tf.setBackground(Color.WHITE);
JPanel buttonPane = new JPanel();
buttonPane.setLayout(new GridLayout(1,3,2,0));
for(int i =0; i < buttonNames.length; ++i)
{
JButton button = new JButton(buttonNames[i]);
button.addActionListener(this);
buttonPane.add(button);
}
panel.add(infoLabel);
panel.add(tf);
panel.add(buttonPane);
JPanel p = new JPanel();
p.setLayout(new GridLayout(1,3,0,0));
p.add(new JLabel(""));
p.add(panel);
p.add(new JLabel(""));
c.add(p);
c.add(new JLabel(""));
this.setResizable(false);
this.setVisible(true);
}
public void actionPerformed(ActionEvent e) {
// TODO Auto-generated method stub
int temp = -1;
for(int i =0; i < buttonNames.length; ++i)
{
if(buttonNames[i].equals(e.getActionCommand()))
{
temp = i;
break;
}
}
switch(temp)
{
//确定
case 0:
isConfirm();
break;
//清除
case 1:
isClear();
break;
//退出
case 2:
isQuit();
break;
}
}
private void isClear()
{
tf.setText("");
tf.repaint();
}
private void isQuit()
{
if(JOptionPane.showConfirmDialog(null,
"Are you sure to quit?", "Confirm",
JOptionPane.YES_NO_CANCEL_OPTION, JOptionPane.INFORMATION_MESSAGE)
== JOptionPane.YES_OPTION)
this.dispose();
}
protected abstract void isConfirm();
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -