| | |
applet
Please support our Java advertiser: Programming Forums - DaniWeb Sister Site
Thread Solved |
•
•
Join Date: Mar 2006
Posts: 78
Reputation:
Solved Threads: 0
Hi,
I am trying to implement an applet.
The idea is to create the applet, then connect places where I single-click with the mouse with black lines until we give a double-click.
With a double-click I should clear the applet.
To clear the applet I am trying to set the color to white and re-draw all the lines so that I have a complete white screen.
The complete code is in attach.
Here is the specific code for the single/double clicks event:
I appreciate your help, cheers,
I am trying to implement an applet.
The idea is to create the applet, then connect places where I single-click with the mouse with black lines until we give a double-click.
With a double-click I should clear the applet.
To clear the applet I am trying to set the color to white and re-draw all the lines so that I have a complete white screen.
The complete code is in attach.
Here is the specific code for the single/double clicks event:
Java Syntax (Toggle Plain Text)
public boolean mouseDown(Event evt, int x, int y) { // initialization Graphics g = getGraphics(); // checks number of clicks if (m_nNumMouseClicks < m_nMAXLOCS) { // checks for double click action if ((lastX==x) && (lastY==y) && ((evt.when-timeMouseDown) < dClkRes)) { System.out.println("double click: CLEAR SCREEN!!!"); // set color a white g.setColor(Color.WHITE); // print the lines in white to hide the black lines for (int i = 0; i < m_nNumMouseClicks - 1; i++) { for (int j = i + 1; j < m_nNumMouseClicks; j++) { g.drawLine(m_dimLocs[i].width, m_dimLocs[i].height, m_dimLocs[j].width, m_dimLocs[j].height); } } // white squre //g.fillRect(0, 0, 400, 400); repaint(); return false; } // single click action else { System.out.println("simple click"); timeMouseDown = evt.when; lastX=x; lastY=y; // record the click location (if there's enough room) m_dimLocs[m_nNumMouseClicks] = new Dimension(x, y); m_nNumMouseClicks++; // now force the window to repaint repaint(); } } return true; }
I appreciate your help, cheers,
•
•
Join Date: Mar 2006
Posts: 78
Reputation:
Solved Threads: 0
Hi again,
I have managed to solve the issue by creating a new field to save the actual color as you can see in the code:
Cheers,
I have managed to solve the issue by creating a new field to save the actual color as you can see in the code:
Java Syntax (Toggle Plain Text)
public boolean mouseDown(Event evt, int x, int y) { // initialization Graphics g = getGraphics(); // checks number of clicks if (m_nNumMouseClicks < m_nMAXLOCS) { // checks for double click action if ((lastX==x) && (lastY==y) && ((evt.when-timeMouseDown) < dClkRes)) { System.out.println("double click: CLEAR SCREEN!!!"); // set color to RED actual = Color.ORANGE; g.setColor(actual); // print the lines in white to hide the black lines for (int i = m_nNumMouseClicks - 2; i < m_nNumMouseClicks - 1; i++) { for (int j = i + 1; j < m_nNumMouseClicks; j++) { g.drawLine(m_dimLocs[i].width, m_dimLocs[i].height, m_dimLocs[j].width, m_dimLocs[j].height); } } repaint(); return false; } // single click action else { System.out.println("simple click"); timeMouseDown = evt.when; lastX=x; lastY=y; // record the click location (if there's enough room) m_dimLocs[m_nNumMouseClicks] = new Dimension(x, y); m_nNumMouseClicks++; // set color to black to draw black lines actual = Color.BLACK; // now force the window to repaint repaint(); } } return true; }
Cheers,
•
•
Join Date: Mar 2006
Posts: 78
Reputation:
Solved Threads: 0
Hello,
The idea of this code is to save the clicked-mouse points and creating a line between the last 2 clicked points. Whenever a double-click the screen should be cleared.
This is all working as it should be, however, when running the program in NetBeans I am receiving this message in the debugger console:
Could yo please give me a hand understanding what's wrong?
I am also attaching the code.
Cheers,
The idea of this code is to save the clicked-mouse points and creating a line between the last 2 clicked points. Whenever a double-click the screen should be cleared.
This is all working as it should be, however, when running the program in NetBeans I am receiving this message in the debugger console:
run:
Exception in thread "AWT-EventQueue-1" java.lang.ArrayIndexOutOfBoundsException: -2
at sess24.NewApplet5.paint(NewApplet5.java:77)
at sun.awt.RepaintArea.paintComponent(RepaintArea.java:248)
at sun.awt.RepaintArea.paint(RepaintArea.java:224)
at sun.awt.windows.WComponentPeer.handleEvent(WComponentPeer.java:306)
at java.awt.Component.dispatchEventImpl(Component.java:4577)
at java.awt.Container.dispatchEventImpl(Container.java:2081)
at java.awt.Component.dispatchEvent(Component.java:4331)
at java.awt.EventQueue.dispatchEvent(EventQueue.java:599)
at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:269)
at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:184)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:174)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:169)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:161)
at java.awt.EventDispatchThread.run(EventDispatchThread.java:122)Could yo please give me a hand understanding what's wrong?
I am also attaching the code.
Cheers,
![]() |
Similar Threads
- Java Applet viewer blinks everytime the init method is used. (Java)
- Java Game Applet Too Small (Java)
- Problem with Yahoo chat applet. (Windows NT / 2000 / XP)
- help!! My applet can't run... Urgent!! (Java)
- where to get the java applet? (Web Browsers)
- applet crashed (Windows NT / 2000 / XP)
- Applet or Application? (Java)
Other Threads in the Java Forum
- Previous Thread: Windows command from within my Java program.
- Next Thread: Java Code Errors
| Thread Tools | Search this Thread |
Tag cloud for applet, clear, draw, event, java
.net 3d actuate ajax apple applet application applications arguments array automation binary birt business c++ calculator capture class classes clear code color compare component consumer convert db design desktop development draw eclipse error event ext file firefox fractal functiontesting game google gui guitesting gxt html image input integer java javafx javascript jetbrains jmf jsp julia linux loop macintosh method michaeljackson microsoft mysql netbeans newbie news panel php problem producer programming project property python recursion recursive return screen security set socket software sort spring springsource ssl string sun swing terminal test threads time transfer tree tutorial twitter web webservices windows wxpython






