Reading records: The first two chapters of core Java (version 8)

Source: Internet
Author: User

I am a beginner in Java. Although I have experience in other languages, I still want to learn java well. Many people say thinking in Java is not suitable for beginners and cannot be understood. I can still understand it. It may be my previous experience. However, whatever the way others come, there are twists and turns. Let's take a look at their opinions. There is also the best core Java in the Basic Books, so I also read it. This is the eighth edition. It can be seen that it is selling so well!

The first two chapters are just like the other books. They introduce the Java history and then configure the environment. In the example in Chapter 2, we can see a SectionCodeThis is the first time I have seen such Java code. I initially determined that it should be a loop like foreach, and g really does.

Public class welcome {public static void main (string [] ARGs) {string [] greeting = new string [3]; greeting [0] = "Welcome to core Java "; greeting [1] = "by Cay horstmann"; greeting [2] = "and Gary Cornell"; for (string G: greeting) system. out. println (g );}}

 

There is also a small example of looking at the figure. This is the first time I came into contact with Java's desktop.Program. I typed the code and ran it quite well,

However, the image is rotated in the label, so it is not very good.

Package test; import Java. AWT. eventqueue; import Java. AWT. event. *; import Java. io. *; import javax. swing. *; public class imageview {public static void main (string [] ARGs) {eventqueue. invokelater (New runnable () {public void run () {jframe frame = new imageviewerframe (); frame. setdefaclocloseoperation (jframe. exit_on_close); frame. setvisible (true) ;}}) ;}} class imageviewerframe extends jframe {public imageviewerframe () {settitle ("imageviewer"); setsize (default_width, default_height ); // use a label to display the images label = new jlabel (); add (Label); // set up the file chooser = new jfilechooser (); chooser. setcurrentdirectory (new file (". "); // set up the menu bar jmenubar menubar = new jmenubar (); setjmenubar (menubar); jmenu menu = new jmenu (" file "); menubar. add (menu); jmenuitem openitem = new jmenuitem ("open"); menu. add (openitem); openitem. addactionlistener (New actionlistener () {public void actionreceivmed (actionevent event) {// show file chooser diser int result = chooser. showopendialog (null); // If file selected, set it as icon of the label if (result = jfilechooser. approve_option) {string name = chooser. getselectedfile (). getpath (); label. seticon (New imageicon (name) ;}}); jmenuitem exititem = new jmenuitem ("exit"); menu. add (exititem); exititem. addactionlistener (New actionlistener () {public void actionreceivmed (actionevent event) {system. exit (0) ;}}) ;}private jlabel label; private jfilechooser chooser; Private Static final int default_width = 300; Private Static final int default_height = 400 ;}

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.