A friendly place for programming greenhorns!
Big Moose Saloon
Search
|
Java FAQ
|
Recent Topics
Register / Login
Win a copy of
The Mikado Method
this week in the
Agile and other Processes
forum!
JavaRanch
»
Java Forums
»
Java
»
Applets
Author
applet with NetBeans
Ib Tlb
Greenhorn
Joined: Mar 20, 2011
Posts: 1
posted
Mar 20, 2011 14:19:06
0
package newPak; import java.awt.Color; import java.awt.Graphics; import java.awt.Graphics2D; import javax.swing.JPanel; public class NewJApplet extends javax.swing.JApplet { public void init() { try { java.awt.EventQueue.invokeAndWait(new Runnable() { public void run() { initComponents(); } }); } catch (Exception ex) { ex.printStackTrace(); } } /** This method is called from within the init() method to * initialize the form. * WARNING: Do NOT modify this code. The content of this method is * always regenerated by the Form Editor. */ @SuppressWarnings("unchecked") // generated code then private void jInternalFrame1MouseMoved(java.awt.event.MouseEvent evt) { this.statusBar.setText(String.format("mouse X:%d Y:%d",evt.getX(),evt.getY())); } private void jInternalFrame1MouseClicked(java.awt.event.MouseEvent evt) { Draw d = new Draw(evt.getX(),evt.getY()); this.jInternalFrame1.add(d); this.jInternalFrame1.validate(); } private java.awt.Graphics g; // Variables declaration - do not modify private javax.swing.JButton jButton1; private javax.swing.JInternalFrame jInternalFrame1; private javax.swing.JPanel jPanel1; private javax.swing.JLabel statusBar; // End of variables declaration } class Draw extends JPanel { private int x; private int y; public Draw(int i,int j){ x=i; y=j; } @Override public void paintComponent(Graphics g) { System.out.println((String.format("mouse clicked at X:%d Y:%d",x,y))); super.paintComponent(g); Graphics2D g2d = (Graphics2D) g; g2d.drawOval(100, 100, 10, 10); System.out.println((String.format("mouse clicked at X:%d Y:%d",x,y))); } }
my problem is here
private void jInternalFrame1MouseClicked(java.awt.event.MouseEvent evt) { Draw d = new Draw(evt.getX(),evt.getY()); this.jInternalFrame1.add(d); this.jInternalFrame1.validate(); }
I want to draw the oval here but nothing is displayed not event the println in the terminal ?
I agree. Here's the link:
http://ej-technologies/jprofiler
- if it wasn't for jprofiler, we would need to run our stuff on 16 servers instead of 3.
subject: applet with NetBeans
Similar Threads
How do I refresh the JFrame or call the paint method without calling initComponents()? :(
how to Draw, mouse dragged points on JPane and Save it
A conundrum with seting Graphics font size
Problem With GUI of Net Beans
Saving a Jpanel as a JPEG
All times are in JavaRanch time: GMT-6 in summer, GMT-7 in winter