Java language program design

xiaoxiao2021-03-06  42

Design Title 2: Write the applet, contain two buttons, a button is used to enlarge a string on the Applet, and a button is used to reduce or narrow the continuous click.

This topic is to utilize SETFONT (F1) in the program, to realize the amplification and reduction of fonts in the applet by changing the value of the variable I in the program. In the program, when you click the button with a mouse, the AWT event handler sends an ActionEvent event object to the button. The application makes the response To implement an ActionListenner interface for the button registration event listener. In the program, the listener is registered with the addActionListener () method. When the program is run, click the two buttons to automatically implement the zoom and reduction of the string.

// enLargeimport java.awt. *;

Import java.awt.event. *;

Public class enLarge Extends WINDOWADAPTER IMPLEments ActionListener {

PRIVATE FRAME F;

PRIVATE PANEL P;

Private Button B1, B2;

Private textfield t;

INT i = 100;

Public static void main (string args []) {

Enlarge be = new enlarge ();

BE.GO ();

Public void Go () {

f = new frame ();

P = new panel ();

T = New Textfield ("Wang Rui", 10);

B1 = New Button ("Zoom");

B2 = New Button ("Reduced");

P.Add (b1);

P.Add (b2);

F.Add ("center", t);

F.Add ("South", P);

F.AddWindowListener (this);

B1.AddActionListener (this);

B2.AddActionListener (this);

F.setsize (300, 300);

F.setVisible (TRUE);

}

// Implement an enlargement reduction function

Public Void ActionPerformed (ActionEvent E) {

IF (E.getsource () == b1) {

i = i 4;

FONT F1 = New font ("Chinese_GB2312", Font.Plain, I); // Setting the font

T.SETFONT (F1);

T.SETTEXT ("Wang Rui");

}

IF (E.getsource () == b2) {

I = I-4;

FONT F1 = New font ("Chinese_GB2312", Font.Plain, i);

T.SETFONT (F1);

T.SETTEXT ("Wang Rui");

}

}

Public void windowClosing (WindowEvent E) {

System.exit (0);

}

}

转载请注明原文地址:https://www.9cbs.com/read-70252.html

New Post(0)