Chapter 3 Applet exercises

xiaoxiao2021-03-06  42

Appletsum.java

/ * * /// appletsum.java - text input. *; Import java.awt.event. *; import javax.swing *;. public class AppletSum extends JApplet implements ActionListener {JTextField inputOne = new JTextField (20); JTextField inputTwo = new JTextField (20); JTextField output = new JTextField (20); public void init () { Container Pane = getContentPane (); Pane.setLayout (new flowLayout ()); Pane.Add ("Enter One Number."); Pane.Add (Inputone); Pane.Add ("Enter A Number and hit return. "); Pane.Add (InputTWO); Pane.Add (" THEIR SUM IS: "); PANE.ADD (OUTPUT); InputTwo.addActionListener (this);} public void ActionPerformed (ActionEvent E) {Double First, Second, Sum; First = Double.Parsedouble (InputOnGetText (); second = double.parsedouble; SUM = first se Cond; output.settext (String.Valueof (SUM));}}

When I change the program as required, although it can be run in Eclipse, it cannot be manually executed in a DOS manner.

import java.awt *;. import java.awt.event *;. import javax.swing *;. public class AppletTriangle extends JApplet implements ActionListener {JTextField inputOne = new JTextField (20); JTextField inputTwo = new JTextField (20); JTextField inputThree = new JTextField (20); JTextField output = new JTextField (20); public void init () {Container pane = getContentPane (); pane.setLayout (new FlowLayout ()); pane.add (new JLabel ( "Enter a Number. "); Pane.Add (INPUTON); PANE.ADD (" Enter a Number. "); Pane.Add (InputTWO); Pane.Add (New Jlabel (" Enter a Number and Hit Return ")); PANE.ADD (Inputthree); Pane.Add (" IS IT A TRIANGLE? "); Pane.Add (Output); InputThree.AddActionListener (this);} public void ActionPerformed (ActionEvent E ) {Double first, second, third; string result; first = double.parsedouble; second = double.pasedouble (in Puttwo.getText (); third = double.parsedouble (InputThree.getText ()); if (First Second> Third &&first Third> Second && Second Third> First) Result = "YES"; else result = " No "; output.settext (result);}} The only problem is that there is no comment. After adding a similar comment, you can execute it in the DOS environment. It seems that different languages, the comments in Java are also related to the operation of the program.

/ * * /

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

New Post(0)
CopyRight © 2020 All Rights Reserved
Processed: 0.037, SQL: 9