Java Course Internship Journal (Tuesday)

Source: Internet
Author: User

Import Java.awt.eventqueue;import javax.imageio.imageio;import Javax.swing.jframe;import Javax.swing.JPanel;import Javax.swing.border.emptyborder;import Javax.swing.abstractbutton;import Javax.swing.imageicon;import Javax.swing.jbutton;import Javax.swing.jfilechooser;import Javax.swing.jtextfield;import Javax.swing.JLabel; Import Java.awt.color;import java.awt.image;import java.awt.systemcolor;import Java.awt.event.ActionListener; Import Java.awt.event.actionevent;import Java.awt.event.mouseadapter;import Java.awt.event.mouseevent;import Java.io.file;import Java.io.filefilter;import Java.io.ioexception;public class Guess2 extends JFrame {/** * *        /private static final long serialversionuid = 1L;    Private JPanel ContentPane;    Private JTextField Tfdir;    Private JTextField Tfclass;   File[] Filearray;    All files under directory int num_img = 0;    Total number of documents int index = 0;    The current file's ordinal String strpath = "";    + directory path String strfilename = ""; + filename JLabel jlbimg = nulL    private int idimg = 1;    JLabel jlbImg1 = null;    JLabel jlbImg2 = null;    JLabel JLBIMG3 = null;     /** * Launch the application.  */public static void main (string[] args) {Eventqueue.invokelater (new Runnable () {public void run ()                    {try {Guess2 frame = new Guess2 ();                Frame.setvisible (TRUE);                } catch (Exception e) {e.printstacktrace ();    }            }        });     }/** * Create the frame.        */Public Guess2 () {settitle ("\u731c\u731c\u770b\u6e38\u620fv0.1");        Setdefaultcloseoperation (Jframe.exit_on_close);        SetBounds (100, 100, 645, 409);        ContentPane = new JPanel ();        Contentpane.setborder (New Emptyborder (5, 5, 5, 5));        Setcontentpane (ContentPane);                Contentpane.setlayout (NULL);        Select the handler for the directory button JButton btndir = new JButton ("\u9009\u62e9\u76ee\u5f55"); Btndir.addActionListener (new ActionListener () {public void actionperformed (ActionEvent arg0) {JFileChooser                   Jfc=new JFileChooser ();                   Jfc.setfileselectionmode (jfilechooser.files_and_directories);                   Jfc.showdialog (New JLabel (), "select");                  File File=jfc.getselectedfile ();                 Tfdir.settext (File.getabsolutepath ()); if (File!=null && file.isdirectory ()) {//Get all Files under directory Filearray = FILE.LISTF                     Iles ();                 num_img = Filearray.length;        }            }        });        Btndir.setbounds (26, 26, 93, 23);                Contentpane.add (Btndir); Text box.        Display directory Tfdir = new JTextField ();        Tfdir.seteditable (FALSE);        Tfdir.setbounds (125, 27, 363, 21);        Contentpane.add (Tfdir);        Tfdir.setcolumns (10);        Select the handler for the class button JButton Btnclass = new JButton ("\u9009\u62e9\u73ed\u7ea7"); BtnclasS.addactionlistener (new ActionListener () {public void actionperformed (ActionEvent e) {JFileChooser                  Jfc=new JFileChooser ();                  Jfc.setfileselectionmode (jfilechooser.files_and_directories);                  Jfc.showdialog (New JLabel (), "select");                File File=jfc.getselectedfile ();                            Tfclass.settext (File.getabsolutepath ());        }        });        Btnclass.setbounds (26, 59, 93, 23);                Contentpane.add (Btnclass);        text box, display class file Tfclass = new JTextField ();        Tfclass.seteditable (FALSE);        Tfclass.setbounds (125, 60, 363, 21);        Contentpane.add (Tfclass);                Tfclass.setcolumns (10);        Label, display with the student name JLabel lbguessname = new JLabel ("\u59d3\u540d");        Lbguessname.setbounds (259, 91, 102, 23);                Contentpane.add (Lbguessname); Label.                Show first student photo final JLabel lblImg1 = new JLabel ("\u56fe\u72471"); Lblimg1.addmoUselistener (New Mouseadapter () {@Override public void mouseclicked (MouseEvent arg0) {        }         });        Lblimg1.setbounds (26, 21, 183, 200);        Contentpane.add (LBLIMG1);        JLBIMG1 = new JLabel ();        Jlbimg1.setbackground (color.red);        Jlbimg1.setbounds (26, 151, 181,201);                                        This.add (JLBIMG1);        Label, showing the second student photo final JLabel lblImg2 = new JLabel ("\u56fe\u72472");                                        Lblimg2.addmouselistener (New Mouseadapter () {@Override public void mouseclicked (MouseEvent e) {        }        });        Lblimg2.setforeground (Color.Black);        Lblimg2.setbackground (systemcolor.inactivecaption);        Lblimg2.setbounds (241, 21, 200, 200);        Contentpane.add (LBLIMG2);        JlbImg2 = new JLabel ();        Jlbimg2.setbackground (color.red);        Jlbimg2.setbounds (240, 155, 183, 201);        This.add (JLBIMG2); Label. Show a third studyRaw Photo final JLabel lblImg3 = new JLabel ("\u56fe\u72473"); Lblimg3.addmouselistener (New Mouseadapter () {@Override public void mouseclicked (MouseEvent        e) {}});        Lblimg3.setbounds (434,21, 200, 200);        Contentpane.add (LBLIMG3);        JLBIMG3 = new JLabel ();        Jlbimg3.setbackground (color.red);        Jlbimg3.setbounds (434, 155, 185, 201);        This.add (JLBIMG3);        Guess the button again, click to update the corresponding three pictures with the student named final JButton btnguessagain = new JButton ("\u518d\u731c\u4e00\u6b21");            Btnguessagain.addactionlistener (new ActionListener () {public void actionperformed (ActionEvent e) {                    if (E.getsource () ==btnguessagain) {//assumed to be nextbutton String strtmp = filearray[index].tostring ();                    index++;                    if (index==num_img) index = 0;    Jlbimg1.seticon (New ImageIcon (strtmp));                                    index++;                    Jlbimg2.seticon (New ImageIcon (strtmp));                    index++;                        if (E.getsource () ==btnguessagain) {//assumed to be nextbutton String STRTMP2 = filearray[index].tostring ();                                               index++;                                                Jlbimg2.seticon (New ImageIcon (STRTMP2));                                   index++;                    }} String StrTmp1 = Filearray[index].tostring ();                    index++;               Jlbimg3.seticon (New ImageIcon (STRTMP1));        }        });        Btnguessagain.setbounds (223, 337, 93, 23);    Contentpane.add (Btnguessagain); }}

Results





Yesterday the second text box has not been able to read. Now I can,

And can display three pictures.

But this progress is not know can be in Friday before the end of guess ....


Java Course Internship Journal (Tuesday)

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.