|
floor host .
Published in:
14:03:35 2015-12-28
Java.awt.event.* import; Javax.swing.* import; Class TeachSearchInfo extends JPanel implements ActionListener {public / / create prompt tag array JLabel[] jlArray new = {JLabel private ("school number:"), JLabel new ("secret code:")}; / / create labels Private JLabel JL = new JLabel ("please enter a number:"); / / create for text input box control number JTextField JTF new = JTextField private (); / / create a query button JButton JB private = JButton new ("query"); / / create for display tag array information JLabel[] jlArray2 new = JLabel[2] private; The statement quoted GetStuInfo / / GetStuInfo getsI private; / / constructor TeachSearchInfo public () { / / initialization interface This.initialFrame (); } / / initialization method of interface Public void (initialFrame) {// will add controls to the container This.setLayout (null); Jl.setBounds (30, 20, 250, 30); This.add (JL); Jtf.setBounds (115, 20, 150, 30); This.add (JTF); Jtf.addActionListener (this); Jb.setBounds (280, 20, 80, 30); This.add (JB); Jb.addActionListener (this); } The actionPerformed / ActionListener interface (method) Void actionPerformed public (E ActionEvent) { If (e.getSource) (e.getSource) (|| = = JB = = JTF) {// query processing code button press Get input number / / Stu_id String = jtf.getText (); If (stu_id.equals ("")) {// number is empty JOptionPane.showMessageDialog (this, "please enter the student number", "error", JOptionPane.ERROR_MESSAGE); Return; The basic information of else {//} method calls GetStuInfo to obtain the specified students Baseinfo String[] = getsi.getBaseInfo (stu_id); If (baseinfo[0] = null) {// if baseinfo[0]==null, indicates that none of the students JOptionPane.showMessageDialog (this, "without the student", "wrong"", JOptionPane.ERROR_MESSAGE); Return; Else {//} update all control interface display This.removeAll (); For (I int = 0; I < 2; i++) { JlArray2[i] = JLabel new (baseinfo[i]); } Jl.setBounds (30, 20, 150, 30); This.add (JL); Jtf.setBounds (115, 20, 150, 30); This.add (JTF); Jb.setBounds (280, 20, 80, 30); This.add (JB); JlArray[0].setBounds (30, 100, 100, 30); This.add (jlArray[0]); JlArray[1].setBounds (30, 150, 100, 30); This.add (jlArray[1]); JlArray2[0].setBounds (130, 100, 150, 30); This.add (jlArray2[0]); JlArray2[1].setBounds (130, 150, 150, 30); This.add (jlArray2[1]); This.repaint (); } } } } Void setFocus public () { This.jtf.requestFocus (true); } } |
Reply times: 0
|