• Introduction to Java Programming - Chapter 13: GraphicsIntroduction to Java Programming - Chapter 13: Graphics

    You learned how to create image icons and display image icons in labels and buttons. For example, the following statements create an image icon and display it in a label: ImageIcon icon = new ImageIcon("image/us.gif"); JLabel jlblImage = new JLabel(imageIcon); An image icon displays a fixed-size image. To display an image in a flexible size, ...

    pdf36 trang | Chia sẻ: dntpro1256 | Ngày: 23/11/2020 | Lượt xem: 620 | Lượt tải: 0

  • Introduction to Java Programming - Chapter 12: GUI BasicsIntroduction to Java Programming - Chapter 12: GUI Basics

    Java uses the javax.swing.ImageIcon class to represent an icon. An icon is a fixed-size picture; typically it is small and used to decorate components. Images are normally stored in image files. You can use new ImageIcon(filename) to construct an image icon. For example, the following statement creates an icon from an image file us.gif in the...

    pdf37 trang | Chia sẻ: dntpro1256 | Ngày: 23/11/2020 | Lượt xem: 619 | Lượt tải: 0

  • Introduction to Java Programming - Chapter 11: Object - Oriented DesignIntroduction to Java Programming - Chapter 11: Object - Oriented Design

    Framework-Based Programming, cont. Once you understand the concept of Java and object-orient programming, the most important lesson from now on is learning how to use the API to develop useful programs. The most effective way to achieve it is to imitate good examples. The book provides many carefully designed examples to demonstrate the conc...

    pdf50 trang | Chia sẻ: dntpro1256 | Ngày: 23/11/2020 | Lượt xem: 680 | Lượt tải: 0

  • Introduction to Java Programming - Chapter 10: Abstract Classes and InterfacesIntroduction to Java Programming - Chapter 10: Abstract Classes and Interfaces

    Arrays are objects. An array is an instance of the Object class. Furthermore, if A is a subclass of B, every instance of A[] is an instance of B[]. Therefore, the following statements are all true: new int[10] instanceof Object new GregorianCalendar[10] instanceof Calendar[]; new Calendar[10] instanceof Object[] new Calendar[10] instanceof O...

    pdf56 trang | Chia sẻ: dntpro1256 | Ngày: 23/11/2020 | Lượt xem: 730 | Lượt tải: 0

  • Introduction to Java Programming - Chapter 9: Inheritance and PolymorphismIntroduction to Java Programming - Chapter 9: Inheritance and Polymorphism

    Hiding Fields and Static Methods, cont. When invoking an instance method from a reference variable, the actual class of the object referenced by the variable decides which implementation of the method is used at runtime. When accessing a field or a static method, the declared type of the reference variable decides which method is used at comp...

    pdf56 trang | Chia sẻ: dntpro1256 | Ngày: 23/11/2020 | Lượt xem: 642 | Lượt tải: 0

  • Introduction to Java Programming - Chapter 8: Strings and Text I/OIntroduction to Java Programming - Chapter 8: Strings and Text I/O

    Write a class named ReplaceText that replaces a string in a text file with a new string. The filename and strings are passed as command-line arguments as follows: java ReplaceText sourceFile targetFile oldString newString For example, invoking java ReplaceText FormatString.java t.txt StringBuilder StringBuffer replaces all the occurrences of ...

    pdf52 trang | Chia sẻ: dntpro1256 | Ngày: 23/11/2020 | Lượt xem: 657 | Lượt tải: 0

  • Introduction to Java Programming - Chapter 7: Objects and ClassesIntroduction to Java Programming - Chapter 7: Objects and Classes

    Creating Windows Using the JFrame Class Objective: Demonstrate using classes from the Java library. Use the JFrame class in the javax.swing package to create two frames; use the methods in the JFrame class to set the title, size and location of the frames and to display the frames.

    pdf58 trang | Chia sẻ: dntpro1256 | Ngày: 23/11/2020 | Lượt xem: 638 | Lượt tải: 0

  • Introduction to Java Programming - Chapter 6: ArraysIntroduction to Java Programming - Chapter 6: Arrays

    Objective: write a program that calculates the total score for students in a class. Suppose the scores are stored in a threedimensional array named scores. The first index in scores refers to a student, the second refers to an exam, and the third refers to the part of the exam. Suppose there are 7 students, 5 exams, and each exam has two parts-...

    pdf40 trang | Chia sẻ: dntpro1256 | Ngày: 23/11/2020 | Lượt xem: 833 | Lượt tải: 0

  • Introduction to Java Programming - Chapter 5: MethodsIntroduction to Java Programming - Chapter 5: Methods

    There are two ways to use classes from a package. • One way is to use the fully qualified name of the class. For example, the fully qualified name for JOptionPane is javax.swing.JOptionPane. For Format in the preceding example, it is com.prenhall.mypackage.Format. This is convenient if the class is used a few times in the program. • The other ...

    pdf37 trang | Chia sẻ: dntpro1256 | Ngày: 23/11/2020 | Lượt xem: 662 | Lượt tải: 0

  • Introduction to Java Programming - Chapter 4: LoopsIntroduction to Java Programming - Chapter 4: Loops

    Example: Displaying Prime Numbers Problem: Write a program that displays the first 50 prime numbers in five lines, each of which contains 10 numbers. An integer greater than 1 is prime if its only positive divisor is 1 or itself. For example, 2, 3, 5, and 7 are prime numbers, but 4, 6, 8, and 9 are not. Solution: The problem can be broken into...

    pdf17 trang | Chia sẻ: dntpro1256 | Ngày: 23/11/2020 | Lượt xem: 701 | Lượt tải: 0