import java.awt.*; import java.applet.*; import java.util.*; import java.awt.event.*; /** * An applet to provide an editor of text. edited by * the panel * @author matth3wbishopyahoo!com */ public class EditApplet extends Applet implements ActionListener { //-------------------------------------------- private StringBuffer file; //-------------------------------------------- private Button btnSave; //-------------------------------------------- private Button btnLoad; //-------------------------------------------- private TextArea taEditArea; //-------------------------------------------- private Label lblMessages; //-------------------------------------------- private Font displayFont; //------------------------------------------------- private Date startTime; //------------------------------------------------- private Date initializeTime; //------------------------------------------------- private Date stopTime; //------------------------------------------------- private Date destroyDate; //------------------------------------------------- Color backgroundColour; //------------------------------------------------- /** initialize method */ public void init() { //super(); this.initializeTime = new Date(); System.out.println("init method of applet"); this.btnSave = new Button("play"); this.btnSave.addActionListener(this); this.btnLoad = new Button("play"); this.btnLoad.addActionListener(this); this.lblMessages = new Label(); this.displayFont = new Font("Monospaced", Font.PLAIN, 16); this.taEditArea = new TextArea("hello text area"); this.taEditArea.setEditable(true); this.taEditArea.setFont(this.displayFont); this.taEditArea.setForeground(Color.WHITE); this.taEditArea.setBackground(Color.BLACK); this.add(this.btnSave); this.add(this.btnLoad); this.add(this.lblMessages); this.add(this.taEditArea); setLayout(new java.awt.GridLayout(1,0)); add(taEditArea); validate(); } //-- method: init //------------------------------------------------- public void start() { this.startTime = new Date(); System.out.println("start method of 'Small' applet"); //addItem("starting... "); } //------------------------------------------------- public void stop() { this.stopTime = new Date(); } //------------------------------------------------- public void destroy() { } //------------------------------------------------- void addItem(String newWord) { //String t = field.getText(); //field.setText(t + newWord); repaint(); } //------------------------------------------------- /* public void paint(Graphics g) { //Draw a Rectangle around the applet's display area. g.drawRect(0, 0, size().width - 1, size().height - 1); //Draw the current string inside the rectangle. g.drawString(buffer.toString(), 5, 15); } */ //-------------------------------------------- public void actionPerformed(ActionEvent e) { Object source = e.getSource(); if (source == this.btnSave) { this.lblMessages.setText("file saved " + (new Date())); } if (source == this.btnLoad) { this.lblMessages.setText("loading "); } } //-- method: actionPerformed //-------------------------------------------- /** A main method to test */ public static void main(String[] args) throws Exception { StringBuffer sbUsageMessage = new StringBuffer(""); sbUsageMessage.append("usage: java EditApplet ."); //sbUsageMessage.append(NEWLINE); if (args.length == 0) { System.out.println(sbUsageMessage); System.exit(-1); } Frame frame = new Frame("Testing EditApplet"); EditApplet eaTest = new EditApplet(); frame.add("Center", eaTest); frame.pack(); frame.show(); } //-- main() } //-- class: EditApplet