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: 978 | 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: 1179 | 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: 966 | 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: 981 | Lượt tải: 0
Formatting Output Use the new JDK 1.5 printf statement. System.out.printf(format, items); Where format is a string that may consist of substrings and format specifiers. A format specifier specifies how an item should be displayed. An item may be a numeric value, character, boolean value, or a string. Each specifier begins with a percent sign
20 trang | Chia sẻ: dntpro1256 | Ngày: 23/11/2020 | Lượt xem: 932 | Lượt tải: 0
Naming Conventions, cont. Class names: – Capitalize the first letter of each word in the name. For example, the class name ComputeArea. Constants: – Capitalize all letters in constants, and use underscores to connect words. For example, the constant PI and MAX_VALUE
55 trang | Chia sẻ: dntpro1256 | Ngày: 23/11/2020 | Lượt xem: 918 | Lượt tải: 0
Two Ways to Invoke the Method There are several ways to use the showMessageDialog method. For the time being, all you need to know are two ways to invoke it. One is to use a statement as shown in the example: JOptionPane.showMessageDialog(null, x, y, JOptionPane.INFORMATION_MESSAGE)); where x is a string for the text to be displayed, and y i...
39 trang | Chia sẻ: dntpro1256 | Ngày: 23/11/2020 | Lượt xem: 962 | Lượt tải: 0
Các loại JDBC Dirvers Drivers thuần java và hiện thực/dùng database protocol để giao tiếp trực tiếp với CSDL. Thường là những JDBC drivers nhanh nhất. Thường dùng socket kết nối trực tiếp với mỗi DBMS khác nhau Client -> JDBC Driver -> Native-protocol JDBC Driver -> database server. Ưu điểm Performance tốt nhất so với các kiểu khác N...
30 trang | Chia sẻ: dntpro1256 | Ngày: 23/11/2020 | Lượt xem: 1033 | Lượt tải: 0
Tạo một node trên cây làm root DefaultMutableTreeNode top = new DefaultMutableTreeNode("The Java Series"); Tạo các node bên dưới DefaultMutableTreeNode category = null; DefaultMutableTreeNode book = null; category = new DefaultMutableTreeNode("Books for Java Programmers"); top.add(category); book = new DefaultMutableTreeNode( “Core Java”);...
56 trang | Chia sẻ: dntpro1256 | Ngày: 23/11/2020 | Lượt xem: 1015 | Lượt tải: 0
Thread Scheduling Ví dụ Tạo lớp kế thừa Thread Sử dụng phương thức sleep() Công việc Tạo 4 thread chạy song sọng, mỗi thread sẽ tạm ngưng thi hành một khoảng thời gian ngẫu nhiên. Sau khi kết thúc sleeping sẽ in ra tên thread
43 trang | Chia sẻ: dntpro1256 | Ngày: 23/11/2020 | Lượt xem: 1118 | Lượt tải: 0