// This is a simple applet that demonstrate
//the functions of buttons in the user-computer
// interactive interface design.

import java.awt.*;

public class button extends java.applet.Applet {

String s = "submit";
String r = "reset";

Button submit = new Button (s);
Button reset = new Button (r);

public void init(){
add(submit);
add(reset);
}

}


 

/*
* Keys.java
*
* Created on October 23, 2002, 7:32 PM
*/

import java.awt.Graphics;
import java.awt.Color;
import java.awt.Event;
import java.awt.Font;


public class Keys extends java.applet.Applet {

char currkey;
int currx;
int curry;

/** Initializes the applet Keys */
public void init () {
initComponents ();
currx = (getSize().width / 2) -8;
curry = (getSize().height /2) -32;
//setBackground(Color.white);
setFont (new Font ("Helvetica", Font.BOLD, 36));
requestFocus();
}


private void initComponents () {//GEN-BEGIN:initComponents
setLayout (new java.awt.BorderLayout ());

}//GEN-END:initComponents


public boolean keyDown (Event eve, int key){
switch (key) {
case Event.DOWN:
curry +=5;
break;
case Event.UP:
curry -=5;
break;
case Event.LEFT:
currx -=5;
break;
case Event.RIGHT:
currx +=5;
break;
default:
currkey = (char)key;
}
repaint ();
return true;
}

public void paint(Graphics g){
if (currkey != 0){
g.drawString(String.valueOf(currkey),currx, curry);
}
}
}


/*
* goURL.java
*
* Created on October 23, 2002, 10:29 PM
*/



import java.awt.*;
import java.net.*;

public class goURL extends java.applet.Applet {

Choice page;
String webPage, pageURL;
String[] holdPage;
String[] holdURL;
int NUMURL = 256;
int i;


/** Initializes the applet goURL */
public void init () {
initComponents ();
page = new Choice();
holdPage = new String[NUMURL];
holdURL = new String[NUMURL];

for (i = 0; i < NUMURL; i++) {
webPage = getParameter("page" + i);
pageURL = getParameter("url" + i);

if ((webPage == null) || (pageURL == null)) break;

holdPage[i] = webPage;
holdURL[i] = pageURL;

page.add(holdPage[i]);
}

add(page);

}

private void initComponents () {//GEN-BEGIN:initComponents
setLayout (new java.awt.BorderLayout ());

}//GEN-END:initComponents


public boolean action(Event e, Object obj) {
int temp;
if(e.target.equals(page)) {
temp = page.getSelectedIndex();

try {
URL u = new URL(holdURL[temp]);
getAppletContext().showDocument(u);
} catch(MalformedURLException ex) {
System.err.println(ex);
}// End catch statement

}// End of if statement

return true;
} //end of action

}// End goURL


/*
* Line3D.java
*
* Created on October 23, 2002, 9:23 PM
*/


import java.awt.*;

public class Line3D extends java.applet.Applet {
int currx; //varible for holding current mouse position X
int curry; // " " " " " " Y
final int MAXPOINT = 1000; //size of array
int pointx[]= new int[MAXPOINT]; //array of int for holding click postions X
int pointy[]= new int[MAXPOINT]; // " " " " " " " Y
int currline; //counter

/** Initializes the applet Line3D */
public void init () {
initComponents ();
currx = curry = currline = 0; //set varibles to 0
//setBackground(Color.red); //sets background color
for(int i = 0; i < MAXPOINT; i++) //loop to set all members of both arrays to 0
pointx[i] = pointy[i] = 0; //sets all to 0
}


private void initComponents () {//GEN-BEGIN:initComponents
setLayout (new java.awt.BorderLayout ());

}//GEN-END:initComponents


// Variables declaration - do not modify//GEN-BEGIN:variables
// End of variables declaration//GEN-END:variables


public void paint(Graphics g) //paint method called y repaint();
{
for(int i=0; i<currline; i++) //loop to draw all array elements
{
if(pointx[i] == 0|| pointy[i] == 0) //dont draw if pints are 0,0
break; //if 0,0 kill loop
else g.drawLine(pointx[i], pointy[i], currx,curry);//draws line to current mouse postion
}
g.drawString("Lines: "+currline, 1, getSize().height-5);
}

public boolean mouseMove(Event e, int x, int y)//called when mouse is moved
{
currx = x; //set currx to mouse postion X
curry = y; //set curry to mouse postion Y
repaint();
return true; //returns true
}
public boolean mouseDown(Event e, int x, int y)//called when mouse is clicked
{
pointx[currline]=x; //adds click X to array
pointy[currline]=y; //adds click Y to array
currline++; //increments C
return true; //returns true
}
public boolean mouseDrag(Event e, int x, int y)//called when the mouse is being dragged
{
// pointx[currline]=x; //sets the draging X to the array
//pointy[currline]=y; // " " " Y " " "
currx=x; //sets the current mouse position X to the draggin point
curry=y; // " " " " " Y " " " "
//currline++; //increments c
repaint(); //calls paint()
return true; //return true
}
}


/*
* checktest.java
*
* Created on October 25, 2002, 11:08 PM
*/
import java.awt.*;

public class checktest extends java.applet.Applet {
BorderLayout b = new BorderLayout ();
Checkbox cbAC = new Checkbox("Air Conditioner");
Checkbox cbSR = new Checkbox("Sun Roof");
Checkbox cbSW = new Checkbox("Steering Wheel");
Checkbox cbT = new Checkbox("Tires");
Label cost = new Label("COST($): ", Label.LEFT);
Label cAC = new Label("510", Label.LEFT);
Label cSR = new Label("2222", Label.LEFT);
Label cSW = new Label("150", Label.LEFT);
Label cT = new Label ("320", Label.LEFT);
Label status = new Label();

/** Initializes the applet checktest */
public void init () {
setLayout (b);
Label title = new Label("Choose from the following items: ");
add(title, BorderLayout.NORTH);
Panel gridPanel = new Panel(new GridLayout(0,2));
gridPanel.add(new Label("ITEMS", Label.CENTER));
gridPanel.add(cost, Label.CENTER);
gridPanel.add(cbAC);
gridPanel.add(cAC);
gridPanel.add(cbSR);
gridPanel.add(cSR);
gridPanel.add(cbSW);
gridPanel.add(cSW);
gridPanel.add(cbT);
gridPanel.add(cT);
add(gridPanel, BorderLayout.CENTER);
add(new Label(" "), BorderLayout.WEST);
add(status, BorderLayout.SOUTH);
}

// public Insets inset(){
// return new Insets(10,10,10,60);
//}

public boolean action(Event e, Object arg){
if (e.target instanceof Checkbox){
computeTotal();
add(status, BorderLayout.SOUTH);
return true;
}
else return false;
}

public void computeTotal(){
int total = 0;
if (cbAC.getState()) total += Integer.parseInt(cAC.getText());
if (cbSR.getState()) total += Integer.parseInt(cSR.getText());
if (cbSW.getState()) total += Integer.parseInt(cSW.getText());
if (cbT.getState()) total += Integer.parseInt(cT.getText());
status.setText("Total Price is " + total + " in US Dollas");
}


/** This method is called from within the init() method to
* initialize the form.
* WARNING: Do NOT modify this code. The content of this method is
* always regenerated by the FormEditor.
*/
private void initComponents () {//GEN-BEGIN:initComponents
setLayout (new java.awt.BorderLayout ());

}//GEN-END:initComponents
}

 

Copyright©2002, All Right Reserved

Department of Geography, San Diego State University