Results 1 to 1 of 1
Thread: Java Graphics
- 01-02-2011, 11:55 PM #1
Member
- Join Date
- Jan 2011
- Posts
- 5
- Rep Power
- 0
Java Graphics
Hi there,
I am new in java, I have school problem stands like this:
Write a code for drawing two lines. By every click, a segment should be drawn which connect the current location with the preview one. The coordinates of the Lines must be stored at Line.txt. Put Buttons for clearing the display, writing the coordinates of the lines and calculating the distance between the lines.
my current code is as follows, but i am missing more than the half of the program, pls any help!!!
the code:
//public void mousePressed(MouseEvent e){}
//public void mouseClicked(MouseEvent e){}
//public void mouseEntered(MouseEvent e){}
//public void mouseExited(MouseEvent e){}
//public void mouseReleased(MouseEvent e){}
//Interface uses the keyword "implements" in the class declaration when it is being used You must implemnet
// all methods of an interface. You can leave empty any unNeeded methods.
//e.g.
import java.awt.*;
import java.awt.event.*;
import java.applet.*;
import javax.swing.*;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.nio.ByteBuffer;
import java.nio.channels.FileChannel;
import java.io.*;
public class MouseTest extends Applet implements MouseListener{
int x, y ;
String tracer;
public MouseTest(){
addMouseListener(this);
setBackground(Color.red);
setPreferredSize(new Dimension(600,600));
}
public void mousePressed(MouseEvent e){
x = e.getX() - 10;
y = e.getY() - 10;
tracer = " x = " + x + " y = " + y;
// repaint the applet
repaint();
}
// dont use these so leave them empty
public void mouseClicked(MouseEvent e){}
public void mouseEntered(MouseEvent e){}
public void mouseExited(MouseEvent e){}
public void mouseReleased(MouseEvent e){}
// paint method
public void paint(Graphics g){
g.drawString(tracer, 100 , 100);
g.drawOval(x,y,20,20);
}
public static void main(String[] args) {
JFrame windo = new JFrame("TESKA ZADACA");
windo.add(new MouseTest());
windo.setDefaultCloseOperation(JFrame.EXIT_ON_CLOS E);
windo.pack();
windo.setVisible(true);
}
}
Similar Threads
-
Please Help! : Java Graphics
By keaton1ao in forum Java 2DReplies: 1Last Post: 11-17-2010, 08:46 PM -
Java Graphics
By keaton1ao in forum New To JavaReplies: 12Last Post: 11-16-2010, 08:19 PM -
Problems with Java 2D example in the book: JAVA 2D Graphics by O'Reilly
By Lil_Aziz1 in forum Java 2DReplies: 2Last Post: 01-16-2010, 04:50 PM -
Java Graphics
By svaidya in forum New To JavaReplies: 8Last Post: 12-07-2009, 05:11 PM -
Want to learn Java Graphics
By loggen in forum New To JavaReplies: 7Last Post: 01-03-2009, 04:15 PM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks