tailieunhanh - Beginning Programming with Java for Dummies 2nd phần 10

Làm thế nào để bạn sử dụng một mật khẩu và đầu vào của người dùng? Bạn kiểm tra xem họ đang như nhau. Đó là lý do tại sao lớp String của Java xác định bằng phương pháp. Một đối tượng có thể được nhiều hơn chỉ là một bó dữ liệu. Với lập trình hướng đối tượng, mỗi đối tượng sở hữu bản sao của các phương pháp sử dụng đối tượng. | 354 Part IV Using Program Units__ Figure 20-5 The frame in Listing 20-2 with the button pressed. As with other programs that use classes from Java s API Listing 20-2 comes with my litany of descriptions and explanations of the classes features. One way or another it s all the same story. Each object has its own data and its own methods. To refer to an object s data or methods use a dot. And to find out more about an object s data or methods use Java s API documentation. Each frame that is each instance of the JFrame class has a setTitle method. If you want get a pencil and add a setTitle column to the JFrame table in Figure 20-2. In Listing 20-2 I make the frame s title be the word Interact as if interacting with this frame makes anything useful happen . You can see Interact in the frame s title bar in Figures 20-4 and 20-5. The JTextField class describes those long white boxes like the box containing the words Type your text here in Figures 20-4 and 20-5. In Listing 20-2 I create a new text field an instance of the JTextField class and I add this new text field to the frame s content pane. When you run the code in Listing 20-2 you can type stuff into the text field. But because I haven t written any code to respond to the typing of text nothing happens when you type. C est la vie. The JButton class describes those clickable things like the thing containing the words This button is temporarily out of order in Figures 20-4 and 20-5. In Listing 20-2 I create a new button an instance of the JButton class and I add this new button to the frame s content pane. When you run the code in Listing 20-2 you can click the button all you want. Because I haven t written any code to respond to the clicking nothing happens when you click the button. For a program that responds to button clicks see the next section. Each Java container has a setLayout method. A call to this method ensures that the doohickeys on the frame are arranged in a .

TỪ KHÓA LIÊN QUAN
crossorigin="anonymous">
Đã phát hiện trình chặn quảng cáo AdBlock
Trang web này phụ thuộc vào doanh thu từ số lần hiển thị quảng cáo để tồn tại. Vui lòng tắt trình chặn quảng cáo của bạn hoặc tạm dừng tính năng chặn quảng cáo cho trang web này.