| | |
applet
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 |
.net 3d addressbook ajax ansi apache api apple applet array assembly automation balls binary binarytree c++ c/c++ class classes clear code component constructor convert design development dragging draw eclipse eclipsedevelopment encryption error event external firefox fractal game google gui html image infinite inheritance input insight integer j2seprojects java javafx javaprojects javascript jetbrains jpanel julia linux login loop loops mergers method microsoft myregfun mysql netbeans newbie news open-source opensource os parsing php print problem programming python random reference rim safari scale set size smart software solaris sort sortedmaps storm subclass sun swing terminal thread threads tree virtualbox web windows wxpython wxwidgets






