Matt Gerrans
Posts: 1153
Nickname: matt
Registered: Feb, 2002
|
|
Re: ok, desperate for help with compile errors
|
Posted: Mar 21, 2002 6:00 PM
|
|
Here is your code, sans compiler errors:
import java.applet.Applet;
import java.awt.*;
import java.awt.event.*;
public class new1 extends Applet implements AdjustmentListener,ItemListener
{
private boolean mouseIn = true;
private Panel bottomPanel;
private Choice choosecolour;
private Color colourX;
private Scrollbar scrollX;
private Scrollbar scrollY;
private Scrollbar scrollBig;
private Scrollbar scrollWide;
int startX = 110;
int startY = 170;
int big = 80;
int wide = 160;
public void init()
{
choosecolour = new Choice();
choosecolour.add("Cyan");
choosecolour.add("Blue");
choosecolour.add("Yellow");
add(choosecolour);
choosecolour.addItemListener(this);
scrollX = new Scrollbar(Scrollbar.HORIZONTAL, 100, 1, 0, 200);
scrollY = new Scrollbar(Scrollbar.VERTICAL, 100, 1, 0, 200);
add(scrollX);
add(scrollY);
scrollX.addAdjustmentListener(this);
scrollY.addAdjustmentListener(this);
scrollBig = new Scrollbar(Scrollbar.HORIZONTAL, 50, 1, 0, 200);
scrollWide = new Scrollbar(Scrollbar.VERTICAL, 100, 1, 0, 200);
add(scrollBig);
add(scrollWide);
scrollBig.addAdjustmentListener(this);
scrollWide.addAdjustmentListener(this);
setLayout(new BorderLayout());
bottomPanel = new Panel();
add("South", bottomPanel);
bottomPanel.setBackground(Color.yellow);
bottomPanel.add(scrollX);
bottomPanel.add(scrollY);
bottomPanel.add(scrollBig);
bottomPanel.add(scrollWide);
}
public void adjustmentValueChanged(AdjustmentEvent e)
{
startX = scrollX.getValue();
startY = scrollY.getValue();
big = scrollBig.getValue();
wide = scrollWide.getValue();
repaint();
}
public void paint(Graphics g)
{
//g.drawString("startX Value is "+startX,10,50);
//g.drawString("startY Value is "+startY,10,80);
//g.drawRect(startX,startY,big,wide);example
g.setColor(Color.blue); //period
g.fillOval(70, 70, 10, 10);
g.setColor(Color.green);
g.fillArc(90, 20, 40, 60, 45, 280); //Outer Arc for E
g.setColor(Color.lightGray);
g.fillArc(100, 29, 20, 40, 45, 360); //Inner Arc for E
g.setColor(Color.green);
g.fillRect(100, 42, 17, 10); //Bar for E
g.setColor(Color.orange); //period
g.fillOval(140, 70, 10, 10);
g.setColor(Color.yellow);
g.fillArc(160, 20, 40, 60, 45, 280); //Outer Arc for C
g.setColor(Color.lightGray);
g.fillArc(170, 29, 20, 40, 45, 360); //Inner Arc for C
g.setColor(Color.magenta); //period
g.fillOval(210, 70, 10, 10);
g.setColor(Color.blue);
g.fillArc(230, 20, 40, 60, 45, 280); //Outer Arc for E
g.setColor(Color.lightGray);
g.fillArc(240, 29, 20, 40, 45, 360); //Inner Arc for E
g.setColor(Color.blue);
g.fillRect(240, 42, 17, 10); //Bar for E
g.setColor(Color.red); //period
g.fillOval(280, 70, 10, 10);
g.setColor(Color.green); //colours moveable rectangle
g.fillRect(startX, startY, big, wide); //gives co ords for starting point
g.setColor(Color.black);
g.drawLine(110, 170, 150, 110); //tower
g.drawLine(150, 110, 190, 170); //tower
g.drawRect(110, 170, 80, 160); //main body
g.setColor(Color.white);
g.fillOval(130, 180, 40, 40); //clock face
g.setColor(Color.black);
g.drawLine(150, 200, 160, 190); //Big Hand
g.drawLine(154, 190, 160, 190);
g.drawLine(160, 190, 160, 195);
g.drawLine(140, 200, 150, 200); //Little Hand
g.drawLine(140, 200, 143, 197);
g.drawLine(140, 200, 143, 203);
g.setColor(Color.red);
g.fillRect(130, 270, 40, 60); //disk
g.setColor(Color.black);
g.fillRect(132, 272, 3, 4);
g.fillRect(163, 272, 3, 4);
g.setColor(Color.gray);
g.fillRect(140, 312, 23, 19); //slide
g.setColor(Color.black);
g.fillRect(143, 317, 6, 9);
g.setColor(Color.red);
g.drawString("LECE, Get London Computing", 80, 350);
}
public void itemStateChanged(ItemEvent e)
{
if(e.getSource() == choosecolour)
{
switch(choosecolour.getSelectedIndex())
{
case 0:
colourX = Color.red;
break;
case 1:
colourX = Color.green;
break;
case 2:
colourX = Color.blue;
break;
}
}
}
public void adjustmentChange(AdjustmentEvent e)
{
// I added this getGraphics() so your code would
// compile, but it is better design to do call
// repaint() and let your paint() method do the
// appropriate rendering based on the current state
// of your object(s).
Graphics g = getGraphics();
if(mouseIn == true)
{
g.setColor(Color.red);
g.fillRect(23, 23, 10, 57); //L
g.fillRect(23, 70, 33, 10);
}
else
{
g.setColor(Color.blue);
g.fillRect(23, 23, 10, 57); //L
g.fillRect(23, 70, 33, 10);
}
}
}
But it still needs work. In particular, you don't ever modify the mouseIn variable, so it will always draw the same color.
|
|