packageshangke;importjava.awt.Dimension;importjava.awt.FlowLayout;importjava.awt.event.ActionEvent;importjava.awt.event.ActionListener;importjava.io.IOException;importshangke.ExampleForHbase;import javax.swing.*;public class test extendsJFrame
{//控件
JLabel jb1 = newJLabel();
JTextField platName= new JTextField(15);
JLabel jb2= newJLabel();
JTextField platNumber= new JTextField(15);
JLabel jb3=newJLabel();
JTextField date= new JTextField(15);
JLabel jb4=newJLabel();
JTextField number= new JTextField(15);
JLabel jb5=newJLabel();
JTextField tec= new JTextField(15);//定义
FlowLayout flow = newFlowLayout();
JTextArea jt1= newJTextArea();
JButton button= newJButton();
JButton button1= newJButton();
JButton button2= newJButton();
JButton button3= newJButton();publictest()
{try{
jbInit();
}catch(Exception e)
{
e.printStackTrace();
}
}private void jbInit()throwsException
{
setSize(new Dimension(260,200));
getContentPane().setLayout(flow);
jb1.setText("平台名称");
platName.setText("");
jb2.setText("平台编号");
platNumber.setText("");
jb3.setText("批准年月");
date.setText("");
jb4.setText("批准文号");
number.setText("");
jb5.setText("技术领域");
tec.setText("");
jt1.setText("");
button.setText("插入");
button1.setText("删除");
button2.setText("修改");
button3.setText("查询");
button.addActionListener(new test_jButton1_actionAdapter(this));
button1.addActionListener(new test_jButton2_actionAdapter(this));
button2.addActionListener(new test_jButton3_actionAdapter(this));
button3.addActionListener(new test_jButton4_actionAdapter(this));this.getContentPane().add(jb1);this.getContentPane().add(platName);this.getContentPane().add(jb2);this.getContentPane().add(platNumber);this.getContentPane().add(jb3);this.getContentPane().add(date);this.getContentPane().add(jb4);this.getContentPane().add(number);this.getContentPane().add(jb5);this.getContentPane().add(tec);this.getContentPane().add(button);this.getContentPane().add(button1);this.getContentPane().add(button2);this.getContentPane().add(button3);
}public static voidmain(String[] args)
{
test test=newtest();
test.setVisible(true);
}
}class test_jButton1_actionAdapter implementsActionListener
{privatetest adaptee;
test_jButton1_actionAdapter(test adaptee)
{this.adaptee=adaptee;
}public voidactionPerformed(ActionEvent e)
{
SwingUtilities.invokeLater(newRunnable()
{public voidrun()
{try{
UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
}catch(Exception e2)
{
e2.printStackTrace();
}
String platName=adaptee.platName.getText();
String platNumber=adaptee.platNumber.getText();//adaptee.jt1.setText("您的用户名是:"+username+"您的输入密码是:"+String.valueOf(pwd));
String date=adaptee.date.getText();
String number=adaptee.number.getText();
String tec=adaptee.tec.getText();try{
ExampleForHbase.insertRow("Test", "1", "platName", "", platName);
ExampleForHbase.insertRow("Test", "1", "platNumber", "", platNumber);
ExampleForHbase.insertRow("Test", "1", "date", "", date);
ExampleForHbase.insertRow("Test", "1", "number", "", number);
ExampleForHbase.insertRow("Test", "1", "tec", "", tec);
JOptionPane.showMessageDialog(adaptee,"插入成功");
}catch(IOException e)
{
e.printStackTrace();
}
}
});
}
}//delete
class test_jButton2_actionAdapter implementsActionListener
{privatetest adaptee;
test_jButton2_actionAdapter(test adaptee)
{this.adaptee=adaptee;
}public voidactionPerformed(ActionEvent e)
{
SwingUtilities.invokeLater(newRunnable()
{public voidrun()
{try{
UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
}catch(Exception e2)
{
e2.printStackTrace();
}
String str=JOptionPane.showInputDialog("请输入要删除的平台编号");try{
ExampleForHbase.deleteRow("Test", "1", "", "");
JOptionPane.showMessageDialog(adaptee,"删除成功");
}catch(IOException e)
{
e.printStackTrace();
}
}
});
}
}//update
class test_jButton3_actionAdapter implementsActionListener
{privatetest adaptee;
test_jButton3_actionAdapter(test adaptee)
{this.adaptee=adaptee;
}public voidactionPerformed(ActionEvent e)
{
SwingUtilities.invokeLater(newRunnable()
{public voidrun()
{try{
UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
}catch(Exception e2)
{
e2.printStackTrace();
}
String str=JOptionPane.showInputDialog("请输入要修改的平台编号");try{if(ExampleForHbase.getData("Test", "1", "platName", "")!=null)
{
ExampleForHbase.deleteRow("Test", "1", "", "");
String str1=JOptionPane.showInputDialog("请输入要修改的平台编号");
String str2=JOptionPane.showInputDialog("请输入要修改的平台名称");
String str3=JOptionPane.showInputDialog("请输入要修改的批准年月");
String str4=JOptionPane.showInputDialog("请输入要修改的批准文号");
String str5=JOptionPane.showInputDialog("请输入要修改的技术领域");
ExampleForHbase.insertRow("Test", "1", "platName", "", str1);
ExampleForHbase.insertRow("Test", "1", "platNumber", "", str2);
ExampleForHbase.insertRow("Test", "1", "date", "", str3);
ExampleForHbase.insertRow("Test", "1", "number", "", str4);
ExampleForHbase.insertRow("Test", "1", "tec", "", str5);
JOptionPane.showMessageDialog(adaptee,"修改成功");
}else{
JOptionPane.showMessageDialog(adaptee,"所要修改的不存在");
}
}catch(IOException e)
{
e.printStackTrace();
}
}
});
}
}//select
class test_jButton4_actionAdapter implementsActionListener
{privatetest adaptee;
test_jButton4_actionAdapter(test adaptee)
{this.adaptee=adaptee;
}public voidactionPerformed(ActionEvent e)
{
SwingUtilities.invokeLater(newRunnable()
{public voidrun()
{try{
UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
}catch(Exception e2)
{
e2.printStackTrace();
}try{
String str=JOptionPane.showInputDialog("请输入要查询的平台编号");
String platName=ExampleForHbase.getData("Test", "1", "platName", "");
String platNumber=ExampleForHbase.getData("Test", "1", "platNumber", "");
String date=ExampleForHbase.getData("Test", "1", "date", "");
String number=ExampleForHbase.getData("Test", "1", "number", "");
String tec=ExampleForHbase.getData("Test", "1", "tec", "");if(platName==null)
{
JOptionPane.showMessageDialog(adaptee,"查询为空");
}else{
JOptionPane.showMessageDialog(adaptee,"平台名称:"+platName+"\n平台编号:"+platNumber+"\n批准年月:"+date+"\n批准文号:"+number+"\n技术领域:"+tec);
}
}catch(IOException e)
{
e.printStackTrace();
}
}
});
}
}