Home > Back-end >  I want to do my homework today, look at how to do?
I want to do my homework today, look at how to do?

Time:12-01

Java awt package
? The structure of the Frame (Frame) class methods
? Public Frame ()
? Public Frame (String title)
Among them, the title of the title specify framework
? Container (Container) class methods
? Public Component the add Component (comp)
A component is added in the container comp
A frame can place multiple components in
? Public void setLayout (LayoutManager MGR)
Set the layout



Javax.mail. Swing package
? JFrame class constructor is as follows:
JFrame () to create no title initial invisible framework,
JFrame (String title) to create a title for the title of the initial invisible framework,
? In order to choose the framework can exit the program when the close button, should add WindowListener listener or write the following code:
Frame. SetDefaultCloseOperation (JFrame. EXIT_ON_CLOSE);
Unlike AWT components, Swing components cannot be directly added to the top-level container, it must be added to the content of the one that is associated with the Swing top container panel (the content pane),
? The JFrame add components there are two ways:
(1) with getContentPane () method to obtain the content of the JFrame panel, and then the join components: frame. The getContentPane (). The add (childComponent)
(2) establish a Jpanel or JDesktopPane middle container, add components to the container, using setContentPane () method to put the container for the content of the JFrame panel:
Jpanel contentPane=new Jpanel ();
//the other components are added to the Jpanel;
Frame. SetContentPane (contentPane);
//the contentPane object is set to become the content of the frame panel












Practice, design interface as shown in figure, the window size for 400, 300, the output is shown in figure,


Exercise 2, design interface as shown in figure, the window size for 200, 150, the title is shown in figure, set the Font to "TimesRoman fonts Font. BOLD, 20, add a" close "button, click the change button, the window closed. (add event listeners)

Practice 3:
Requirements: use DataOutputStream class to write a set of data in a tray below the invoic E. TXT file,
Program structure:
Asked to write data is three arrays, the content is as follows:
String descs []={" shirt "and" backpack "},
Double prices []={150.24, 100.3},
12, 8 int units []={}
Steps:
In "e:/invoic. TXT" as a parameter to create a file output stream object wf;

2. To wf as parameters to create a dw data output stream object;

3. Write each loop value of each element in the array to the file (here according to the different array types call different ways to write)



Four. Randomly generated 10 random integer (1-100), each produces a random integer is written to a file d: \ suiji TXT, required documents by size of data in order,
(random method (int) (Math. The random () * 100) + 1, using input and output streams and file class)


Five, in accordance with the format "mm - dd yyyy -" display the current time of computer, and display the distance you my birthday how many days apart, save the results and displayed to the c: \ riqi.
in the docCreate directories and files (using the Flie class, using SimpleDateFormat commonly used method to construct a SimpleDateFormat (String patterm, the construction method can use the pattern specifies the format to create an object, the object calling format (Data date) method formatting objects date)

CodePudding user response:

Homework or do not understand to ask

CodePudding user response:

Because do not understand, so just ask

CodePudding user response:

1
 package Kaoshi. 
import javax.swing.*;
Public class kangkang1 {
Public static void main (String [] args) {
JFrame n=new JFrame (" student information management system ");
System. The out. Println (JF method, for example, "");
N.s etSize (400300);
System. The out. Println (" call setSize method ");
N.s etLocation (200200);
N.s etVisible (true);
System. The out. Println (" call setVisible ");
}
}


The second question
 package Kaoshi. 
import java.awt.*;
import java.awt.event.*;
Public class kangkang2 {
Public static void main (String [] args) {
Frame f=new Frame (" window title ");
F.s etFont (new Font (" TimesRoman ", the Font, BOLD, 20));
F.s etLayout (new FlowLayout (FlowLayout. CENTER, 20, 30));
F.s etSize (200150);
F.s etLocation (300200);
F.s etVisible (true);
The Button BTN=new Button (" close ");
F.a dd (BTN);
BTN. AddMouseListener (new MouseAdapter () {
Public void mouseClicked (MouseEvent e) {
System. The exit (0);
}
});


The third topic
 package Kaoshi. 
import java.io.*;
Import the Java. Util. *;
Public class DataOutputStream {
Public static void main (String [] args) throws IOException {
FileReader wf=null;
FileWriter dw=null;
Try {
The File srcFile=new File (" E:/invoic. TXT ");
The File destFile=new File (" E:/invoic. TXT ");
Wf=new FileReader (srcFile);
Dw=new FileWriter (destFile);
Char [] ch=new char [5];
int len;
While ((len=wf. Read (ch))!=1) {
Dw. Write (ch, 0, len);
}
} the catch (IOException e) {
e.printStackTrace();
} the finally {
Try {
If (wf!=null)
Dw. The close ();
} the catch (IOException e) {
System. The out. Println (e);
}
Try {
If (wf!=null)
Wf. Close ();
} the catch (IOException e) {
System. The out. Println (e);
}
}

}
}


The fourth topic
 
Package Kaoshi.

import java.io.FileOutputStream;
import java.io.IOException;
import java.util.ArrayList;
Import the Java. Util. Collections;
Import the Java. Util. Random;

Public class kangkang4 {
Public static void main (String [] args) throws IOException {
FileOutputStream fos=new FileOutputStream (" d: \ \ suiji TXT ");
ArrayList Array=new ArrayList<> (a);
The Random r=new Random ();
for (int i=0; I & lt; 10; I++) {
Array. The add (r.n extInt (100) + 1);
}
The Collections. Sort (array);
for (int i=0; I & lt; Array. The size (); I++) {
String s="";
S +=array. Get (I);
Fos. Write (s.g etBytes ());
Fos. Write (", "getBytes ());
}


fos.close();
}
}


5
 
Package Kaoshi.

import java.io.FileOutputStream;
import java.io.IOException;
nullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnull
  • Related