| ||||||||
|
This page contains examples, associated HTML, and code for some Java Applets. javasamps.zip - contains a number of examples (including those below) of various Java examples.
Hello Demo
The code: HTML:
Code: import java.awt.*;
import java.applet.Applet;
public class hello extends Applet{
String invalue;
public void init() {
invalue = getParameter("invariable");
}
public void paint(Graphics g) {
String s;
s = "This is a string";
g.setColor (Color.blue);
g.fillRect (0, 0, size().width, size().height);
Font f = new Font("Ariel", Font.PLAIN, 14);
g.setFont(f);
g.setColor (Color.white);
g.drawString("This is my demo..." + s, 10, 100);
g.drawString(invalue, 10, 130);
}
}
Input/Output Demo
HTML:
Code: import java.awt.*;
import java.awt.event.*;
import java.applet.Applet;
public class inout extends Applet {
TextField t = new TextField(10);
public void init() {
setLayout(new FlowLayout(FlowLayout.LEFT, 10, 10));
add(new Label("Enter number:"));
add(t);
Button b = new Button("Click Here Add 100");
add(b);
ActionListener listener = new btnListener();
b.addActionListener(listener);
}
public class btnListener implements ActionListener {
public void actionPerformed (ActionEvent e) {
String s = t.getText();
long val1;
val1 = Long.parseLong(s) + 100;
t.setText (Long.toString(val1,10));
}
}
}
|
|
Copyright © 1999
- 2005 |