ThePlace

Home ] Search ] Resources ] Site Map ] Contact Me ]
Dave's Information Technology Resource

Up ]

--- Java Examples ---

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:

<BODY>
<H1>Hello Demo</H1>
<P>
<APPLET CODE="hello.class" WIDTH=300 HEIGHT=300 id="hello">
<param name="invariable" value="This is from the html file">
</APPLET>
</BODY>

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:

<BODY>
<H1>Input/Output Demo</H1>
<P>
<APPLET CODE="inout.class" WIDTH=500 HEIGHT=100 id="inout">
</APPLET>
</BODY>

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));
  }
 }
 }

 

 

 

 

Home ] Up ] Computer Architecture ] Programming Bootcamp ] Database Bootcamp ] Visual BasicS ] Web Basics ] Web Multimedia ] Web Programming ] Advanced Web Topics ] Developing Web Sites ] XML Technology ] Web Glossary ]

Copyright © 1999 - 2005 
ThePlace - Written and Sponsored by Dave Hillman