?? useradd.java
字號(hào):
import javax.swing.*;
import javax.swing.event.*;
import java.awt.*;
import java.awt.event.*;
public class UserAdd extends JFrame implements ActionListener
{
JPanel panel;
JLabel nameLabel;
JLabel telLabel;
JTextField name;
JTextField tel;
JButton sub;
JButton cancel;
Container container;
public UserAdd()
{
super("添加聯(lián)系人");
panel=new JPanel();
name=new JTextField(10);
tel=new JTextField(10);
nameLabel=new JLabel("姓名:");
telLabel=new JLabel("手機(jī)號(hào):");
sub=new JButton("確定");
sub.addActionListener(this);
cancel=new JButton("取消");
cancel.addActionListener(this);
Box telBox=Box.createHorizontalBox();
telBox.add(nameLabel);
telBox.add(Box.createHorizontalStrut(19));
telBox.add(name);
telBox.add(Box.createHorizontalGlue());
Box contentBox=Box.createHorizontalBox();
contentBox.add(telLabel);
contentBox.add(Box.createHorizontalStrut(5));
contentBox.add(tel);
contentBox.add(Box.createHorizontalGlue());
Box buttonBox=Box.createHorizontalBox();
buttonBox.add(Box.createHorizontalStrut(30));
buttonBox.add(sub);
buttonBox.add(Box.createHorizontalStrut(30));
buttonBox.add(cancel);
buttonBox.add(Box.createHorizontalGlue());
Box box=Box.createVerticalBox();
box.add(telBox);
box.add(Box.createVerticalStrut(10));
box.add(contentBox);
box.add(Box.createVerticalStrut(10));
box.add(buttonBox);
box.add(Box.createVerticalStrut(10));
panel.add(box);
setContentPane(panel);
setBounds(120,120,300,160);
setVisible(true);
}
public void actionPerformed(ActionEvent e)
{
if(e.getSource()==sub)
{
String nameStr;
String telStr;
nameStr=name.getText().trim();
telStr=tel.getText().trim();
if(nameStr.equals(""))
{
JOptionPane.showMessageDialog(null, "姓名不能為空");
}
else if(telStr.equals(""))
{
JOptionPane.showMessageDialog(null, "手機(jī)號(hào)不能為空");
}
else
{
DataConn conn=new DataConn();
String sql="insert into friends(name,telphone) values('"+nameStr+"','"+telStr+"')";
if(conn.SqlInsert(sql))
{
JOptionPane.showMessageDialog(null, "添加聯(lián)系人成功??!");
}
else
{
JOptionPane.showMessageDialog(null, "添加聯(lián)系人失??!請(qǐng)檢查是否存在同名");
}
}
}
if(e.getSource()==cancel)
{
this.dispose();
}
}
}
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號(hào)
Ctrl + =
減小字號(hào)
Ctrl + -