通讯录源代码.docx
- 文档编号:24362815
- 上传时间:2023-05-26
- 格式:DOCX
- 页数:38
- 大小:24.21KB
通讯录源代码.docx
《通讯录源代码.docx》由会员分享,可在线阅读,更多相关《通讯录源代码.docx(38页珍藏版)》请在冰豆网上搜索。
通讯录源代码
importjava.awt.Color;
importjava.awt.event.ActionEvent;
importjava.awt.event.ActionListener;
importjavax.swing.JButton;
importjavax.swing.JFrame;
importjavax.swing.JLabel;
importjavax.swing.JOptionPane;
importjavax.swing.JPanel;
importjavax.swing.JPasswordField;
importjavax.swing.JTextField;
publicclassdengluextendsJFrameimplementsActionListener{
privateJPanelp;
privateJLabelname,pwd;
privateJTextFieldtxtName;
privateJPasswordFieldtxtPwd;
privateJButtonb1,b2;
publicdenglu(){
super("登录界面");
p=newJPanel();
p.setLayout(null);
p.setBackground(Color.red);
name=newJLabel("用户名");
name.setBounds(30,30,60,25);
txtName=newJTextField(20);
txtName.setBounds(95,30,120,25);
p.add(name);
p.add(txtName);
pwd=newJLabel("密码");
pwd.setBounds(30,60,60,25);
txtPwd=newJPasswordField(20);
txtPwd.setEchoChar('*');
txtPwd.setBounds(95,60,120,25);
p.add(pwd);
p.add(txtPwd);
b1=newJButton("确定");
b1.setBounds(45,90,60,25);
b1.addActionListener(this);
b2=newJButton("取消");
b2.setBounds(105,90,60,25);
b2.addActionListener(this);
p.add(b1);
p.add(b2);
this.add(p);
this.setSize(250,170);
this.setLocation(300,300);
this.setResizable(false);
this.setDefaultCloseOperation(EXIT_ON_CLOSE);
this.setVisible(true);
}
publicstaticvoidmain(String[]args){
//TODOAuto-generatedmethodstub
newdenglu();
}
@Override
publicvoidactionPerformed(ActionEvente){
//TODOAuto-generatedmethodstub
Objects=e.getSource();
if(s==b1){
b1Click();
}
if(s==b2){
b2Click();
}
}
privatevoidb1Click(){
Stringusername=txtName.getText();
Stringuserped=newString(txtPwd.getPassword());
if(username.equals("孙茂玮")&&userped.equals("1234")){
newMenuDemo();
//JOptionPane.showMessageDialog(b1,"密码或者用户名错误","提示",JOptionPane.WARNING_MESSAGE);
}
else
JOptionPane.showMessageDialog(b1,"密码或者用户名错误","提示",JOptionPane.WARNING_MESSAGE);
}
privatevoidb2Click(){
txtName.getText();
txtPwd.getPassword();
}
}
importjava.awt.Color;
importjava.awt.event.ActionEvent;
importjava.awt.event.ActionListener;
importjava.awt.event.ItemEvent;
importjava.awt.event.ItemListener;
importjavax.swing.JFrame;
importjavax.swing.JMenu;
importjavax.swing.JMenuBar;
importjavax.swing.JMenuItem;
importjavax.swing.JOptionPane;
importjavax.swing.JPanel;
importjavax.swing.KeyStroke;
publicclassMenuDemoextendsJFrameimplementsActionListener{
privateJPaneljp;
privateJMenuBarmenuBar;
privateJMenumenuFile,menuHelp;
privateJMenuItemmiadd,midelete,miselect,miExit,miinfo,mii;
publicMenuDemo(){
super("菜单");
this.setSize(300,200);
this.setLocation(400,300);
jp=newJPanel();
jp.setBackground(Color.ORANGE);
menuBar=newJMenuBar();
menuBar.setBackground(Color.orange);
this.setJMenuBar(menuBar);
menuFile=newJMenu("选择功能(F)");
menuHelp=newJMenu("帮助(H)");
//menuFile.addItemListener(this);
menuBar.add(menuFile);
menuBar.add(menuHelp);
menuFile.addSeparator();//添加分割线
miadd=newJMenuItem("添加联系人(A)");
miadd.addActionListener(this);
mii=newJMenuItem("查询单个(O)");
mii.addActionListener(this);
midelete=newJMenuItem("删除联系人(D)");
midelete.addActionListener(this);
miselect=newJMenuItem("查询(S)");
miselect.addActionListener(this);
miExit=newJMenuItem("退出(E)");
//miExit.addActionListener(this);
miExit.addActionListener(newActionListener(){
publicvoidactionPerformed(ActionEvente){
Object[]options={"是的,我要退出","不好意思,点错了"};
intoption=JOptionPane.showOptionDialog(null,"您确定要退出吗?
",
"退出提示....",JOptionPane.OK_CANCEL_OPTION,JOptionPane.WARNING_MESSAGE,
null,options,options[0]);
if(option==JOptionPane.OK_OPTION){
System.exit(0);
}
}
});
miinfo=newJMenuItem("系统介绍");
miinfo.addActionListener(this);
menuFile.add(miadd);
menuFile.add(midelete);
menuFile.add(mii);
menuFile.add(miselect);
menuFile.add(miExit);
menuHelp.add(miinfo);
this.add(jp);
this.setDefaultCloseOperation(EXIT_ON_CLOSE);
this.setVisible(true);
}
publicstaticvoidmain(String[]args){
newMenuDemo();
}
publicvoidactionPerformed(ActionEvente){
JMenuItemitem=(JMenuItem)e.getSource();
if(item==miadd){
newPeople();
}
if(item==midelete){
newdelete();
}
if(item==miselect){
newSelect();
}
if(item==mii){
newselect_one();
}
//if(item==miExit){
//miExit.addActionListener(newActionListener()
//{
//publicvoidactionPerformed(ActionEvente)
///{
//System.exit(0);
//}
//});
//miExit.setMnemonic('Q');
//miExit.setAccelerator(KeyStroke.getKeyStroke('Q',java.awt.Event.CTRL_MASK,true));
//}
if(item==miinfo){
newHelpTest();
}
}
}
importjava.awt.Color;
importjava.awt.event.ActionEvent;
importjava.awt.event.ActionListener;
importjavax.swing.JFrame;
importjavax.swing.JMenu;
importjavax.swing.JMenuBar;
importjavax.swing.JMenuItem;
importjavax.swing.JPanel;
publicclassSelectextendsJFrameimplementsActionListener{
privateJPaneljp;
privateJMenuBarmenuBar;
privateJMenumenuFile;
privateJMenuItemm1,m2,m3,m4,m5;
publicSelect(){
super("分组查询");
this.setSize(300,200);
this.setLocation(400,300);
jp=newJPanel();
jp.setBackground(Color.DARK_GRAY);
menuBar=newJMenuBar();
menuBar.setBackground(Color.orange);
this.setJMenuBar(menuBar);
menuFile=newJMenu("分组(F)");
//menuFile.addItemListener(this);
menuBar.add(menuFile);
menuFile.addSeparator();//添加分割线
m1=newJMenuItem("家人(J)");
m1.addActionListener(this);
m2=newJMenuItem("同学(T)");
m2.addActionListener(this);
m3=newJMenuItem("朋友(P)");
m3.addActionListener(this);
m4=newJMenuItem("其它(O)");
m4.addActionListener(this);
m5=newJMenuItem("");
menuFile.add(m1);
menuFile.add(m2);
menuFile.add(m3);
menuFile.add(m4);
menuFile.add(m5);
this.add(jp);
this.setDefaultCloseOperation(EXIT_ON_CLOSE);
this.setVisible(true);
}
publicvoidactionPerformed(ActionEvente){
JMenuItemitem=(JMenuItem)e.getSource();
if(item==m1){
newselectConnection("select*fromjiaren");
}
if(item==m2){
newselectConnection("select*fromtongxue");
}
if(item==m3){
newselectConnection("select*fromfriend");
}
if(item==m4){
newselectConnection("select*fromPeople");
}
}
publicstaticvoidmain(String[]args){
newSelect();
}
}
importjava.awt.Color;
importjava.sql.Connection;
importjava.sql.DriverManager;
importjava.sql.ResultSet;
importjava.sql.SQLException;
importjava.sql.Statement;
importjavax.swing.JButton;
importjavax.swing.JFrame;
importjavax.swing.JPanel;
importjavax.swing.JTextField;
//importjava.sql.SQLException;
publicclassselectConnectionextendsJFrame{
privatestaticfinalintEXIT_ON_CLOSE=0;
protectedJTextFieldjf;
protectedJPaneljp;
//protectedJLabellabel1,label2,label3,label4;
//protectedJTextFieldfield1,field2,field3,field4;
protectedJButtonb1,b2;
publicselectConnection(Strings){
super("查询");
this.setSize(600,400);
this.setLocation(400,300);
jp=newJPanel();
//StringSs=s;
//Stringsql="select*fromPeople";
jp.setLayout(null);
jp.setBackground(Color.CYAN);
//field1=newJTextField(10);
//field1.setBounds(30,30,120,30);
//field2=newJTextField(10);
//field2.setBounds(150,30,120,30);
//field3=newJTextField(10);
//field3.setBounds(270,30,120,30);
//field4=newJTextField(10);
//field4.setBounds(390,30,120,30);
//jp.add(field1);
//jp.add(field2);
//jp.add(field3);
//jp.add(field4);
try{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
}catch(ClassNotFoundExceptione){
//TODOAuto-generatedcatchblock
e.printStackTrace();
}
try{
Connectionconn=DriverManager.getConnection("jdbc:
odbc:
sun");
Statementstat=conn.createStatement();
ResultSetrs=stat.executeQuery(s);
intx=30,y=30;
while(rs.next()){
jf=newJTextField();
jf.setBounds(x,y,500,30);
Stringstr1=rs.getString
(1);
Stringstr2=rs.getString
(2);
Stringstr3=rs.getString(3);
Stringstr4=rs.getString(4);
jf.setText("姓名:
"+str1+""+"电话号码:
"+str2+""+"电子邮件:
"+str3+""+"家庭住址:
"+str4);
jp.add(jf);
y+=30;
}
stat.close();
conn.close();
}catch(SQLExceptione){
//TODOAuto-generatedcatchblock
e.printStackTrace();
}
this.add(jp);
this.setResizable(false);
//this.setDefaultCloseOperation(EXIT_ON_CLOSE);
this.setVisible(true);
}
//publicstaticvoidmain(String[]args){
////TODOAuto-generatedmethodstub
//newSelectTest();
//
//}
}
importjava.awt.Color;
importjava.awt.FlowLayout;
importjava.awt.event.ActionEvent;
importjava.awt.event.ActionListener;
importjava.awt.event.ItemEvent;
importjava.awt.event.ItemListener;
importjava.sql.Connection;
importjava.sql.DriverManager;
importjava.sql.SQLException;
importjava.sql.Statement;
importjavax.swing.JButton;
importjavax.swing.JComboBox;
importjavax.swing.JFrame;
importjavax.swing.JLabel;
importjavax.swing.JOptionPane;
importjavax.swing.JTextField;
importjavax.swing.JPanel;
importjavax.swing.plaf.basic.BasicButtonListener;
publicclassselect_oneextendsJFrameimplementsActionListener,ItemListener{
//Stringsql="deletefromPeoplewhereName=field1.getText()";
privateJFramejf;
privateJPaneljp;
privateJComboBoxjc;
privateJLabellabel1,label2;
privateJTextFieldfield1;
pri
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- 通讯录 源代码
![提示](https://static.bdocx.com/images/bang_tan.gif)