Java by API/javax.swing/JApplet — различия между версиями
Admin (обсуждение | вклад) м (1 версия) |
|
(нет различий)
|
Текущая версия на 14:19, 31 мая 2010
Содержание
JApplet: destroy()
import java.awt.Graphics;
import javax.swing.JApplet;
public class MainClass extends JApplet {
String str = "";
public void init() {
str += "init; ";
}
public void start() {
str += "start; ";
}
public void stop() {
str += "stop; ";
}
public void destroy() {
System.out.println("destroy");
}
public void paint(Graphics g) {
g.drawString(str, 10, 25);
}
}
JApplet: init()
import java.awt.Graphics;
import javax.swing.JApplet;
public class MainClass extends JApplet {
String str = "";
public void init() {
str += "init; ";
}
public void start() {
str += "start; ";
}
public void stop() {
str += "stop; ";
}
public void destroy() {
System.out.println("destroy");
}
public void paint(Graphics g) {
g.drawString(str, 10, 25);
}
}
JApplet: paint(Graphics g)
import java.awt.Graphics;
import javax.swing.JApplet;
public class MainClass extends JApplet {
String str = "";
public void init() {
str += "init; ";
}
public void start() {
str += "start; ";
}
public void stop() {
str += "stop; ";
}
public void destroy() {
System.out.println("destroy");
}
public void paint(Graphics g) {
g.drawString(str, 10, 25);
}
}
import javax.swing.JApplet;
import javax.swing.JMenu;
import javax.swing.JMenuBar;
import javax.swing.JMenuItem;
public class MenuApplet extends JApplet {
public void init() {
JMenuBar menubar = new JMenuBar();
JMenu menuFile = new JMenu("File");
JMenuItem openItem = new JMenuItem("Open");
menuFile.add(openItem);
JMenuItem saveItem = new JMenuItem("Save");
menuFile.add(saveItem);
menubar.add(menuFile);
JMenu menuHelp = new JMenu("Help");
JMenuItem aboutItem = new JMenuItem("About");
menuHelp.add(aboutItem);
menubar.add(menuHelp);
setJMenuBar(menubar);
}
}
JApplet: showStatus(String text)
import java.applet.AppletContext;
import java.awt.Graphics;
import java.net.URL;
import javax.swing.JApplet;
public class MainClass extends JApplet {
public void paint(Graphics g) {
AppletContext ac = getAppletContext();
try {
URL url = new URL("http://www.jexp.ru");
ac.showDocument(url, "frame2");
} catch (Exception e) {
showStatus("Exception: " + e);
}
g.drawString("ShowDocument Applet", 10, 25);
}
}
JApplet: start()
import java.awt.Graphics;
import javax.swing.JApplet;
public class MainClass extends JApplet {
String str = "";
public void init() {
str += "init; ";
}
public void start() {
str += "start; ";
}
public void stop() {
str += "stop; ";
}
public void destroy() {
System.out.println("destroy");
}
public void paint(Graphics g) {
g.drawString(str, 10, 25);
}
}
JApplet: stop()
import java.awt.Graphics;
import javax.swing.JApplet;
public class MainClass extends JApplet {
String str = "";
public void init() {
str += "init; ";
}
public void start() {
str += "start; ";
}
public void stop() {
str += "stop; ";
}
public void destroy() {
System.out.println("destroy");
}
public void paint(Graphics g) {
g.drawString(str, 10, 25);
}
}