📄 karl.java
字号:
jl[8]=new JLabel("QQ.Num:");
jl[9]=new JLabel("Email:");
jl[10]=new JLabel("Tel.Num:");
jl[11]=new JLabel("Mobilephone:");
jl[12]=new JLabel("Postalcode:");
jl[13]=new JLabel("Address:");
jl[14]=new JLabel("");
for(int i=0;i<=14;i++){
jl[i].setFont(new Font("Dialog",Font.BOLD,13));
}
/*******/
jp[0].setLayout(new BorderLayout());
jp[0].add(jb[0]);
jp[1].setLayout(new FlowLayout(FlowLayout.RIGHT));
jp[1].add(jl[0]);
jp[2].setLayout(new FlowLayout(FlowLayout.RIGHT));
jp[2].add(jl[1]);
jp[3].setLayout(new FlowLayout(FlowLayout.RIGHT));
jp[3].add(jl[2]);
jp[4].setLayout(new FlowLayout(FlowLayout.RIGHT));
jp[4].add(jl[3]);
jp[5].setLayout(new FlowLayout(FlowLayout.RIGHT));
jp[5].add(jl[4]);
jp[6].setLayout(new FlowLayout(FlowLayout.RIGHT));
jp[6].add(jl[5]);
jp[7].setLayout(new FlowLayout(FlowLayout.RIGHT));
jp[7].add(jl[6]);
jp[8].setLayout(new GridLayout(7,1,5,5));
for(int i=1;i<8;i++){
jp[8].add(jp[i]);
}
jp[9].setLayout(new FlowLayout(FlowLayout.RIGHT));
jp[9].add(jt[0]);
jp[10].setLayout(new FlowLayout(FlowLayout.RIGHT));
jp[10].add(jt[1]);
jp[11].setLayout(new FlowLayout(FlowLayout.RIGHT));
jp[11].add(jt[2]);
jp[12].setLayout(new FlowLayout(FlowLayout.RIGHT));
jp[12].add(jt[3]);
jp[13].setLayout(new FlowLayout(FlowLayout.RIGHT));
jp[13].add(jt[4]);
jp[14].setLayout(new FlowLayout(FlowLayout.RIGHT));
jp[14].add(jt[5]);
jp[15].setLayout(new FlowLayout(FlowLayout.RIGHT));
jp[15].add(jt[6]);
jp[16].setLayout(new GridLayout(7,1,5,5));
for(int i=9;i<16;i++){
jp[16].add(jp[i]);
}
jp[17].setLayout(new FlowLayout(FlowLayout.RIGHT));
jp[17].add(jl[7]);
jp[18].setLayout(new FlowLayout(FlowLayout.RIGHT));
jp[18].add(jl[8]);
jp[19].setLayout(new FlowLayout(FlowLayout.RIGHT));
jp[19].add(jl[9]);
jp[20].setLayout(new FlowLayout(FlowLayout.RIGHT));
jp[20].add(jl[10]);
jp[21].setLayout(new FlowLayout(FlowLayout.RIGHT));
jp[21].add(jl[11]);
jp[22].setLayout(new FlowLayout(FlowLayout.RIGHT));
jp[22].add(jl[12]);
jp[23].setLayout(new FlowLayout(FlowLayout.RIGHT));
jp[23].add(jl[13]);
jp[24].setLayout(new GridLayout(7,1,5,5));
for(int i=17;i<24;i++){
jp[24].add(jp[i]);
}
jp[25].setLayout(new FlowLayout(FlowLayout.RIGHT));
jp[25].add(jt[7]);
jp[26].setLayout(new FlowLayout(FlowLayout.RIGHT));
jp[26].add(jt[8]);
jp[27].setLayout(new FlowLayout(FlowLayout.RIGHT));
jp[27].add(jt[9]);
jp[28].setLayout(new FlowLayout(FlowLayout.RIGHT));
jp[28].add(jt[10]);
jp[29].setLayout(new FlowLayout(FlowLayout.RIGHT));
jp[29].add(jt[11]);
jp[30].setLayout(new FlowLayout(FlowLayout.RIGHT));
jp[30].add(jt[12]);
jp[31].setLayout(new FlowLayout(FlowLayout.RIGHT));
jp[31].add(jt[13]);
jp[32].setLayout(new GridLayout(7,1,5,5));
for(int i=25;i<32;i++){
jp[32].add(jp[i]);
}
jp[33].setLayout(new GridLayout(1,4));
jp[33].add(jp[8]);
jp[33].add(jp[16]);
jp[33].add(jp[24]);
jp[33].add(jp[32]);
jp[34].setLayout(new FlowLayout());
jp[34].add(jb[1]);
jp[34].add(jb[2]);
jp[34].add(jb[4]);
/****************/
jp[35].setLayout(new BorderLayout());
jp[35].add(jp[0],"North");
jp[35].add(jp[33],"Center");
jp[35].add(jp[34],"South");
/****************/
Container c=f.getContentPane();
c.add(jp[35]);
f.setIconImage(image);
f.pack();
f.setSize(500,430);
f.setResizable(false);
f.addWindowListener(new WindowAdapter(){
public void windowClosing(WindowEvent e){
f.dispose();
try{
Thread.sleep(2);
}catch(Exception e1){}
Karl lili=new Karl();
lili.go();
}
});
Dimension screenSize=Toolkit.getDefaultToolkit().getScreenSize();
Dimension frameSize=f.getSize();
f.setLocation( (screenSize.width - frameSize.width) / 2,
(screenSize.height - frameSize.height) / 2);
f.setVisible(true);
for(int i=0;i<=5;i++){
jb[i].addMouseMotionListener(this);
jb[i].addActionListener(this);
}
f.show();
/************************************************/
String []columnNames={"Relation","Name","Nickname","Sex","Birthday","Hobby","Strongpoint"," Headship","QQNum","Email","TelNum","Mobilephone","Postalcode","Address"};
Object[][]rowData=new Object[40][14];
Connection con;
Statement sql;
ResultSet rs;
try{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
}catch(ClassNotFoundException e){}
try{
con=DriverManager.getConnection("jdbc:odbc:SEC","sa","");
sql=con.createStatement();
rs=sql.executeQuery("select * from friend");
int i=0;
while (rs.next()){
rowData[i][0]=rs.getString(1);
rowData[i][1]=rs.getString(2);
rowData[i][2]=rs.getString(3);
rowData[i][3]=rs.getString(4);
rowData[i][4]=rs.getString(5);
rowData[i][5]=rs.getString(6);
rowData[i][6]=rs.getString(7);
rowData[i][7]=rs.getString(8);
rowData[i][8]=rs.getString(9);
rowData[i][9]=rs.getString(10);
rowData[i][10]=rs.getString(11);
rowData[i][11]=rs.getString(12);
rowData[i][12]=rs.getString(13);
rowData[i][13]=rs.getString(14);
i++;
}
}catch(Exception e10){}
fshow=new JFrame("Address List--Author(Karl)");
Image image1=Toolkit.getDefaultToolkit().getImage("7.jpg");
showtable=new JTable(rowData,columnNames);
showtable.setFont(new Font("Dialog",Font.BOLD,15));
/*jp[36].add(new JScrollPane(showtable),BorderLayout.CENTER);*/
jp[37].setLayout(new FlowLayout());
jp[37].add(jb[3]);
jp[37].add(jl[14]);
jp[37].add(jt[14]);
jp[37].add(jb[5]);
jp[38].setLayout(new BorderLayout());
jp[38].add(new JScrollPane(showtable),"Center");
jp[38].add(jp[37],"South");
Container c1=fshow.getContentPane();
c1.add(jp[38]);
fshow.setIconImage(image1);
fshow.pack();
fshow.setSize(900,420);
fshow.setResizable(false);
fshow.addWindowListener(new WindowAdapter(){
public void windowClosing(WindowEvent e){
fshow.dispose();
try{
Thread.sleep(20);
}catch(Exception e1){}
new Linkman();
}
});
Dimension frameSize1=fshow.getSize();
fshow.setLocation( (screenSize.width - frameSize1.width) / 2,
(screenSize.height - frameSize1.height) / 2);
fshow.setVisible(false);
}
/*overwrite the method in the interface which has been implemented*/
public void mouseDragged(MouseEvent e){}
public void mouseMoved(MouseEvent e){
for(int i=0;i<6;i++){
jb[i].setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
}
}
public void actionPerformed(ActionEvent e){
String s=e.getActionCommand();
Connection con=null;
Statement sql=null;
ResultSet rs=null;
try{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
}catch(Exception e4){}
try{
con=DriverManager.getConnection("jdbc:odbc:SEC","sa"," ");
sql=con.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,ResultSet.CONCUR_UPDATABLE);
rs=sql.executeQuery("select * from friend");
}
catch(Exception e5){System.out.print(e5);}
if(s.equals("Show all records?")){
jb[0].setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
f.setVisible(false);
fshow.setVisible(true);
Dimension screenSize=Toolkit.getDefaultToolkit().getScreenSize();
Dimension frameSize1=fshow.getSize();
fshow.setLocation( (screenSize.width - frameSize1.width) / 2,
(screenSize.height - frameSize1.height) / 2);
}
if(s.equals("Add")){
jb[1].setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
try{
sql.executeUpdate("insert into friend values("+"'"+
jt[0].getText()+"'"+","+"'"+
jt[1].getText()+"'"+","+"'"+
jt[2].getText()+"'"+","+"'"+
jt[3].getText()+"'"+","+"'"+
jt[4].getText()+"'"+","+"'"+
jt[5].getText()+"'"+","+"'"+
jt[6].getText()+"'"+","+"'"+
jt[7].getText()+"'"+","+"'"+
jt[8].getText()+"'"+","+"'"+
jt[9].getText()+"'"+","+"'"+
jt[10].getText()+"'"+","+"'"+
jt[11].getText()+"'"+","+"'"+
jt[12].getText()+"'"+","+"'"+
jt[13].getText()+"'"+")");
JOptionPane.showMessageDialog(f,"Record has been added,you can see it nex time");
jt[0].setText("");
jt[1].setText("");
jt[2].setText("");
jt[3].setText("");
jt[4].setText("");
jt[5].setText("");
jt[6].setText("");
jt[7].setText("");
jt[8].setText("");
jt[9].setText("");
jt[10].setText("");
jt[11].setText("");
jt[12].setText("");
jt[13].setText("");
}
catch(Exception e0){
System.out.print(e0);JOptionPane.showMessageDialog(f,"Name can not be null!");}
}
if(s.equals("Cancel")){
jb[2].setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
jt[0].setText("");
jt[1].setText("");
jt[2].setText("");
jt[3].setText("");
jt[4].setText("");
jt[6].setText("");
jt[5].setText("");
jt[7].setText("");
jt[8].setText("");
jt[9].setText("");
jt[10].setText("");
jt[11].setText("");
jt[12].setText("");
jt[13].setText("");
}
if(s.equals("Delete?")){
jb[3].setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
jt[14].setEditable(true);
jl[14].setText("Enter the name of the linkman:");
}
if(s.equals("Close")){
jb[4].setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
f.dispose();
try{
Thread.sleep(20);
}catch(Exception e1){}
Karl lili=new Karl();
lili.go();
}
if(s.equals("Submit")){
jb[5].setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
try{
String s1=jt[14].getText();
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -