hello.java
with the flawed Java code shown
here:
class Hi { public static void main (string[] args) { System.out.println("Hi "+ args[0]) } }
java Hi everybody java hello everybody java Hi java Hi Ana and Bob java Hi "Ana and Bob"
Button
.
To create a new button, say with name b and with the
text push me, use:
The methodb = new Button("push me");
setLabel
can be used to change the text
on the button. For example,
to change the text from push me into thank you use:
Use the last example of the echo applet to write a Java applet with a "push me" button, i.e., a button that changes its label from push me to thank you when pressed. It should look like:b.setLabel("thank you");
To work with the color red, yellow, and green, you have to know the following:
Color
class is of course for working with colors. The
Color.red
object is the red color, and for the other colors
you have similar names.equals
method. For example
will test if the colorColor c = Color.red; c.equals(Color.yellow);
c
is yellow and will return false
.
setBackground
method. For example,
gives a red applet.setBackground(Color.red);