1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 |
/* Change Button Font Example This java example shows how to change button's font using AWT Button class. */ import java.applet.Applet; import java.awt.Button; import java.awt.Font; /* <applet code="ChangeButtonFontExample" width=200 height=200> </applet> */ public class ChangeButtonFontExample extends Applet{ public void init(){ //create buttons Button button1 = new Button("Button 1"); Button button2 = new Button("Button 2"); /* * To change font of a button use * setFont(Font f) method. */ Font myFont = new Font("Courier", Font.ITALIC,12); button1.setFont(myFont); //add buttons add(button1); add(button2); } } |
Example Output
without main how this code will execute?
you obviously need main and in main you will create an instance of the changebuttonfont class.
ahooo.daso daso…..yak
OpenJDK-8-jdk: javac compile without error.
Java ChangeButtonFontExample output error:
…
ksomov@UB18X64:~/JDK8/AWT$ java ChangeButtonFontExample
Error: Main method not found in class ChangeButtonFontExample, please define the main method as:
public static void main(String[] args)
or a JavaFX application class must extend javafx.application.Application
ksomov@UB18X64:~/JDK8/AWT$
Please, help me.
…
Understood… It is necessary to start in the browser which supports Java Applet.
It is necessary to create a file: ChangeButtonFontExample.html и открыть его в браузере:
ChangeButtonFontExample
If your browser was Java-enabled, a “ChangeButtonFontExample” message would appear here.