
September 27th, 2002, 01:44 PM
|
 |
Contributing User
|
|
Join Date: May 2001
Location: Belgium
Posts: 39
Time spent in forums: 3 m 48 sec
Reputation Power: 8
|
|
|
Prob with stupid exercise from school
underneath is an excercise in model viewer stuff of java (the 1.1 model)
you need to build 2 canvasses a control-panel with 5 buttons and a canvas for painting a square on with the size of the value on the button (my english is crap  )
the buttons have to be in an array (she showed it with button[1], button[2] but whats the point of that????...)
this source-code isn't complete yet but try to expalin me
PHP Code:
package modelviewconoef1;
import java.awt.*;
import java.awt.event.*;
import java.applet.*;
public class clsOef1 extends Applet {
private paintCanvas paintBoard;
//private controlsPanel controlPanel;
//initialize applet
public void init(){
setLayout(new BorderLayout());
//paintCanvas = new Canvas(controlPanel);
/*
controlPanel = new Panel();
add(controlPanel,BorderLayout.NORTH);
*/
}
/*
public void paint(Graphics g){
paintBoard = new paintCanvas(10);
paintBoard.paint(g);
}
*/
}
class paintCanvas extends Canvas{
private int sideSquare = 0;
private Color bgColor = Color.orange;
private Color fgColor = Color.blue;
private int posX = 50;
private int posY = 50;
//constructor
paintCanvas(int sideSquare){
this.sideSquare = sideSquare;
//Set Background for canvas
setBackground(this.bgColor);
}
public void paint(Graphics g){
g.setColor(this.fgColor);
g.fillRect(this.posX,this.posY,this.posX + this.sideSquare,this.posY + this.sideSquare);
}
}
class controlPanel extends Panel{
private paintCanvas paintBoard;
private Button[] controlButton = new Button[4];
private ???? postion = new ...[4] //has to be aan array with the places of the button
controlPanel(paintCanvas paintBoard){
this.paintBoard = paintBoard;
for(int i = 0;i < controlButton.length ;i++){
this.controlButton[i] = new Button("" + i * 10);
this.controlButton[i].addActionListener(new controlPanelHandler(i*10));
// here has to go the place of the button
add(this.controlButton[i],????????);
}
}
}
class controlPanelHandler implements ActionListener{
private int sideSquare;
controlPanelHandler(int sideSquare){
this.sideSquare = sideSquare;
}
// this has to be the action handler but it gives an error because he doesnt knwo paintBoard...
public void actionPerformed(ActionEvent e){
paintBoard.sideSquare = this.sideSquare;
paintBoard.repaint();
}
}
I tried to clearify the meaning as good as possible.
but imho the lessons in JAVA an any other programming-language (Visual basic  )SUX in our school
does anyone know good tutorials on the net ( I'm interested in making a chatapplet... but I want to learn something not copy-paste source-code ....
sincerely
|