View Single Post
  #1 (permalink)  
Old 03-11-2008, 02:54 AM
adam87 adam87 is offline
Member
 
Join Date: Mar 2008
Posts: 3
adam87 is on a distinguished road
Basic Face Application
Hey, I'm currently at University and been given a task to make a simple face application that you change the colour of face and also change the size of the face. So far i've got this:

Quote:
// <applet code=RedGreen1.class
// width=200 height=150></applet>

import java.applet.Applet;
import java.awt.*;
import java.awt.event.*;

public class RedGreen1 extends Applet
implements ActionListener, AdjustmentListener
{
private int diameter = 40;
private Color color = Color.red;
private Button red, green;
private Scrollbar slider;
private int sliderValue;

public void init()
{
Label sliderLabel = new Label("Size:");
add(sliderLabel);
slider = new Scrollbar(Scrollbar.HORIZONTAL,
20, 1, 0, 101);
add(slider);
slider.addAdjustmentListener(this);
sliderValue = slider.getValue();
red = new Button("Red");
add(red);
red.addActionListener(this);
green = new Button("Green");
add(green);
green.addActionListener(this);
}

public void paint(Graphics g)
{
g.setColor(color);
g.fillOval(40, 40, sliderValue, sliderValue);
g.setColor(color.black);
g.fillOval(45, 45, 5, 5);
g.fillOval(52, 45, 5, 5);
g.fillOval(50, 50, 2, 2);

}

public void actionPerformed(ActionEvent event)
{
if (event.getSource() == red)
color = Color.red;
if (event.getSource() == green)
color = Color.green;
repaint();
}

public void
adjustmentValueChanged(AdjustmentEvent e)
{
sliderValue = slider.getValue();
repaint();
}
}
There are a couple bits I am unsure about the fist is changing the deafult size of the face.

Secondly I would like the slider thange change all parts of the face and keep it in ratio.

Any help will be appreciated

Adam Huxtable
Reply With Quote
Sponsored Links