"Java Program Internship" Diary (Wednesday) __java

Source: Internet
Author: User

Because I did not read the teacher published on the "Guess" game and scoring criteria, so yesterday and the day before the CSDN published on the Curriculum internship Diary.

The first to second day of the course internship, I was mainly 16 weeks did not complete the work to continue to complete, by the way to realize the "guess" game of the general thinking.

Although after two days of thinking, with the practice of the game idea, but also has the action, but still did not have the game's wrinkle to depict. Now the completed part is limited to the game guessing the interface and the button, and the code is from the first two weeks of homework and classmate's code to come over.

The results of today's progress are shown below:



Attached code:

<span style= "FONT-SIZE:18PX;"

>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 Guess02 extends JFrame {/** * */private static final long serialversionuid = 1L;
    Private JPanel ContentPane;
    Private JTextField Tfdir;
    Private JTextField Tfclass;   File[] Filearray;    All files under folder int num_img = 0;    Total number of documents int index = 0; Serial number of the current file private intidimg = 1;
    JLabel jlbImg1 = null;
    JLabel jlbImg2 = null;
    JLabel JLBIMG3 = null;
     /** * Launch the application.  
            */class Myfilefilter implements filefilter{@Override public boolean accept (File pathname) {  
            String filename = Pathname.getname (). toLowerCase ();  
            if (Filename.contains (". jpg")) {return false;  
            }else{return true;
            }} public static void Main (string[] args) {Eventqueue.invokelater (new Runnable () {
                    public void Run () {try {Guess02 frame = new Guess02 ();
                Frame.setvisible (TRUE);
                catch (Exception e) {e.printstacktrace ();
    }
            }
        });
     }/** * Create the frame.
        * * Public Guess02 () {settitle ("Guess the game V0.1"); Setdefaultcloseoperation (Jframe.exiT_on_close);
        SetBounds (100, 100, 645, 409);
        ContentPane = new JPanel ();
        Contentpane.setborder (New Emptyborder (5, 5, 5, 5));
        Boundary layout device, (5 rows 5 columns) Setcontentpane (ContentPane);
        Contentpane.setlayout (NULL);
        Select the handler for the directory button JButton btndir = new JButton ("select Directory");
            	 Btndir.addactionlistener (new ActionListener () {public void actionperformed (ActionEvent arg0) {  
                 JFileChooser jfc=new JFileChooser ();  
                 Jfc.setfileselectionmode (jfilechooser.files_and_directories);  
                 Jfc.showdialog (New JLabel (), "OK"); 
                 File File=jfc.getselectedfile ();
                 Tfdir.settext (File.getabsolutepath ()); 
                     if (File!=null && file.isdirectory ()) {//reference: Use of File.listfiles (FileFilter) FileFilter in Java
                     
                     http://zhouzaibao.iteye.com/blog/347557;
         Get all the files under the folder       	 
                     Filearray = File.listfiles ();
                 num_img = Filearray.length;
        }
            }
        });
        Btndir.setbounds (26, 26, 93, 23);
        The starting point of the X component on the container x-axis; Y: The component's starting point on the y-axis; width: the length of the component; height: the level of the component.
        
        Contentpane.add (Btndir);
        text box, showing 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 ("Select Class"); Btnclass.addactionlistener (new ActionListener () {public void actionperformed (ActionEvent e) {JF  
                Ilechooser jfc=new JFileChooser ();  
                Jfc.setfileselectionmode (jfilechooser.files_and_directories);  
                Jfc.showdialog (New JLabel (), "OK");
                File File=jfc.getselectedfile ();
                
         Tfclass.settext (File.getabsolutepath ());   }
        });
       
        Btnclass.setbounds (26, 59, 93, 23);
        
        Contentpane.add (Btnclass);
        text box, showing class file Tfclass = new JTextField ();
        Tfclass.seteditable (FALSE);
        Tfclass.setbounds (125, 60, 363, 21);
        Contentpane.add (Tfclass);
        
        Tfclass.setcolumns (10);
        Label, show with guess student name JLabel lbguessname = new JLabel ("name");
        Lbguessname.setbounds (259, 91, 102, 23);
        
        Contentpane.add (Lbguessname);
        
        Label, showing the first student photo final JLabel lblImg1 = new JLabel ("Picture 1"); Lblimg1.addmouselistener (New Mouseadapter () {@Override public void mouseclicked (MouseEvent arg0)
        {
            	
            } 
        });
        Lblimg1.setbounds (26, 151, 183, 172);
        Contentpane.add (LBLIMG1);
        JLBIMG1 = new JLabel ();
        Jlbimg1.setbackground (color.red);
        Jlbimg1.setbounds (26, 151, 183, 172);
        
        
     This.add (JLBIMG1);   The label, which shows the second student photo final JLabel lblImg2 = new JLabel ("Picture 2");
            	
                
            Lblimg2.addmouselistener (New Mouseadapter () {@Override public void mouseclicked (MouseEvent e) {
        }
        });
        Lblimg2.setforeground (Color.Black);
        Lblimg2.setbackground (systemcolor.inactivecaption);
        Lblimg2.setbounds (229, 151, 183, 172);
        Contentpane.add (LBLIMG2);
        JlbImg2 = new JLabel ();
        Jlbimg2.setbackground (color.red);
        Jlbimg2.setbounds (229, 151, 183, 172);
        This.add (JLBIMG2);
        Label, show third student photo final JLabel lblImg3 = new JLabel ("Picture 3"); Lblimg3.addmouselistener (New Mouseadapter () {@Override public void mouseclicked (Mouseev
        ent e) {}});
        Lblimg3.setbounds (434, 151, 183, 172);
        Contentpane.add (LBLIMG3);
        JLBIMG3 = new JLabel (); Jlbimg3.setbackgrounD (color.red);
        Jlbimg3.setbounds (434, 151, 183, 172);
        This.add (JLBIMG3);
        Once again, click the button, then update the corresponding three pictures with a guess student name final JButton btnguessagain = new JButton ("continue to guess");
            	Btnguessagain.addactionlistener (new ActionListener () {public void actionperformed (ActionEvent e) {
                    if (E.getsource () ==btnguessagain) {//If the Next button 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) {//If the Next button} 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); }}</span>


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.