Tổng hợp tài liệu, ebook Kỹ Thuật Lập Trình tham khảo.
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, ...
36 trang | Chia sẻ: dntpro1256 | Ngày: 23/11/2020 | Lượt xem: 620 | Lượt tải: 0
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...
37 trang | Chia sẻ: dntpro1256 | Ngày: 23/11/2020 | Lượt xem: 619 | Lượt tải: 0
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...
50 trang | Chia sẻ: dntpro1256 | Ngày: 23/11/2020 | Lượt xem: 680 | Lượt tải: 0
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...
56 trang | Chia sẻ: dntpro1256 | Ngày: 23/11/2020 | Lượt xem: 730 | Lượt tải: 0
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...
56 trang | Chia sẻ: dntpro1256 | Ngày: 23/11/2020 | Lượt xem: 642 | Lượt tải: 0
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 ...
52 trang | Chia sẻ: dntpro1256 | Ngày: 23/11/2020 | Lượt xem: 657 | Lượt tải: 0
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.
58 trang | Chia sẻ: dntpro1256 | Ngày: 23/11/2020 | Lượt xem: 638 | Lượt tải: 0
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-...
40 trang | Chia sẻ: dntpro1256 | Ngày: 23/11/2020 | Lượt xem: 833 | Lượt tải: 0
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 ...
37 trang | Chia sẻ: dntpro1256 | Ngày: 23/11/2020 | Lượt xem: 662 | Lượt tải: 0
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...
17 trang | Chia sẻ: dntpro1256 | Ngày: 23/11/2020 | Lượt xem: 701 | Lượt tải: 0