i do the programe which is about the draw line but it doesn't work. it just can draw one line but it doesn't continue draw next line. Also i don't know how to do the Level one
================================================ /** * A class to draw specified shapes on a graphical user interface. * The purpose of this class is to demonstrate the use of some of the GUI components form awt. * @author Phil Sheridan * @version 1.0 last update 19/7/1 */
import java.awt.*; import java.awt.event.*;
public class CCurveGUI extends Panel implements ActionListener,MouseListener { public CCurveCanvas theCanvas; private TextField theLevel; private TextField theMessage; private Button theDrawButton; private Button theDrawNextButton; private Choice theColour; private int curlevel =0;
public CCurveGUI( ) { makeTheComponents( ); doTheLayout( ); addTheListeners(); }
// Make all the objects private void makeTheComponents( ) { theCanvas = new CCurveCanvas(); theCanvas.setBackground(Color.yellow); theCanvas.setSize(500,500); theLevel = new TextField("0",5); theLevel.setEditable(false); theMessage = new TextField(20); theDrawButton = new Button("Draw"); theDrawNextButton = new Button("Draw Next"); theColour = new Choice(); theColour.add("Red"); theColour.add("Blue"); }
// Layout all the objects private void doTheLayout( ){ setLayout(new GridLayout(1,2)); Panel left = new Panel(); Panel right = new Panel(); add(left); add(right); left.add(theCanvas); right.setLayout(new FlowLayout()); right.add(theColour); right.add(theDrawButton); right.add(theDrawNextButton); right.add(new Label("Level")); right.add(theLevel); right.add(new Label("Message")); right.add(theMessage); }
public void addTheListeners(){ theDrawButton.addActionListener(this); theDrawNextButton.addActionListener(this); theCanvas.addMouseListener(this); } public void actionPerformed( ActionEvent e ) { if (e.getSource()==theDrawButton){ theCanvas.setParams(theColour.getSelectedItem()); }else{ theCanvas.nextLevel(theColour.getSelectedItem()); //increase leve counter //theLevel.setText(); }
} public void mouseReleased( MouseEvent e ) {} public void mouseEntered( MouseEvent e ) {} public void mouseClicked( MouseEvent e ) {} public void mouseExited( MouseEvent e ) {} public void mouseMoved( MouseEvent e ) {}
public void mousePressed(MouseEvent e){ int x = e.getX(); int y = e.getY(); theCanvas.setCoords(x,y); }
public void makeNewValues(int x1, int y1, int x2, int y2, int level, Graphics g){ int[][] newArray = new int[2][value[0].length * 2 - 1]; for(int i=0,j=0;i<array.length;i++,j+=2){ xm= (values[0]+ values[1]+ values[0][i+1]-values[1][i+1])/2; ym= (values[0]+ values[1]+ values[0][i+1]+values[1][i+1])/2; /*x1=value[0]; x2=value[0][i+1]; y1=value[1][j]; y2=value[1][j+1]; xm=(x1+x2+yi-yi)/2;