Results 1 to 3 of 3
Thread: Whiteboard GUI
- 11-16-2011, 06:41 AM #1
Member
- Join Date
- Oct 2011
- Posts
- 7
- Rep Power
- 0
Whiteboard GUI
I need help to fix my current Whiteboard program. You can compile it and run it, but does not currently do everything I want it to. My whiteboard currently has 3 function, Circle, Rectangle, and Erase. When Circle, Rectangle, or Erase is click it will print the word "Circle", "Rectangle" or "Erase on a 'Text area'. This currently works. I also need to implement mouseListener, when it enter,exit, click, dragged and display the coordinates or it. This is the part I need help with. I already handed this assignment in but I need it to work 100% before moving on because my next assignment that is already given makes me to actually draw the Circle if circle is clicked on and so on.
Java Code:package whiteboard; /** * * @author tvt5043 */ public class whiteEx extends javax.swing.JFrame { /** Creates new form whiteEx */ public whiteEx() { initComponents(); } /** This method is called from within the constructor to * initialize the form. * WARNING: Do NOT modify this code. The content of this method is * always regenerated by the Form Editor. */ @SuppressWarnings("unchecked") // <editor-fold defaultstate="collapsed" desc="Generated Code"> private void initComponents() { tempLable = new javax.swing.JLabel(); rectangleButton = new javax.swing.JButton(); circleButton = new javax.swing.JButton(); eraseButton = new javax.swing.JButton(); textArea = new javax.swing.JTextField(); enterButton = new javax.swing.JButton(); setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE); rectangleButton.setText("Rectangle"); rectangleButton.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { rectangleButtonActionPerformed(evt); } }); circleButton.setText("Circle"); circleButton.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { circleButtonActionPerformed(evt); } }); eraseButton.setText("Erase"); eraseButton.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { eraseButtonActionPerformed(evt); } }); textArea.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { textAreaActionPerformed(evt); } }); enterButton.setText("ENTER"); enterButton.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { enterButtonActionPerformed(evt); } }); whiteEx layout = new whiteEx(getContentPane()); getContentPane().setLayout(layout); layout.setHorizontalGroup( layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING) .add(layout.createSequentialGroup() .addContainerGap() .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING) .add(layout.createSequentialGroup() .add(54, 54, 54) .add(tempLable, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 121, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE) .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED, 137, Short.MAX_VALUE) .add(rectangleButton)) .add(org.jdesktop.layout.GroupLayout.TRAILING, layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING, false) .add(org.jdesktop.layout.GroupLayout.TRAILING, eraseButton, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) .add(org.jdesktop.layout.GroupLayout.TRAILING, circleButton, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 105, Short.MAX_VALUE)) .add(layout.createSequentialGroup() .add(70, 70, 70) .add(textArea, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 254, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE) .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED) .add(enterButton))) .addContainerGap()) ); layout.setVerticalGroup( layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING) .add(layout.createSequentialGroup() .addContainerGap() .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.TRAILING) .add(tempLable, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 25, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE) .add(rectangleButton)) .addPreferredGap(org.jdesktop.layout.LayoutStyle.UNRELATED) .add(circleButton) .add(9, 9, 9) .add(eraseButton) .add(18, 18, 18) .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE) .add(enterButton) .add(textArea, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 37, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)) .addContainerGap(org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)) ); pack(); }// </editor-fold> private void rectangleButtonActionPerformed(java.awt.event.ActionEvent evt) { tempLable.setText(" Rectangle"); } private void circleButtonActionPerformed(java.awt.event.ActionEvent evt) { tempLable.setText(" Circle"); } private void eraseButtonActionPerformed(java.awt.event.ActionEvent evt) { tempLable.setText(" Earse"); } private void textAreaActionPerformed(java.awt.event.ActionEvent evt) { } private void enterButtonActionPerformed(java.awt.event.ActionEvent evt) { tempLable.setText(textArea.getText()); } /** * @param args the command line arguments */ public static void main(String args[]) { java.awt.EventQueue.invokeLater(new Runnable() { public void run() { new whiteEx().setVisible(true); } }); } // Variables declaration - do not modify private javax.swing.JButton circleButton; private javax.swing.JButton enterButton; private javax.swing.JButton eraseButton; private javax.swing.JButton rectangleButton; private javax.swing.JLabel tempLable; private javax.swing.JTextField textArea; // End of variables declaration }
- 11-16-2011, 06:45 AM #2
Member
- Join Date
- Oct 2011
- Posts
- 7
- Rep Power
- 0
Re: Whiteboard GUI
I need help to fix my current Whiteboard program. You can compile it and run it, but does not currently do everything I want it to. My whiteboard currently has 3 function, Circle, Rectangle, and Erase. When Circle, Rectangle, or Erase is click it will print the word "Circle", "Rectangle" or "Erase on a 'Text area'. This currently works. I also need to implement mouseListener, when it enter,exit, click, dragged and display the coordinates or it. This is the part I need help with. I already handed this assignment in but I need it to work 100% before moving on because my next assignment that is already given makes me to actually draw the Circle if circle is clicked on and so on.
Java Code:package whiteboard; /** * * @author tvt5043 */ public class whiteEx extends javax.swing.JFrame { /** Creates new form whiteEx */ public whiteEx() { initComponents(); } /** This method is called from within the constructor to * initialize the form. * WARNING: Do NOT modify this code. The content of this method is * always regenerated by the Form Editor. */ @SuppressWarnings("unchecked") // <editor-fold defaultstate="collapsed" desc="Generated Code"> private void initComponents() { tempLable = new javax.swing.JLabel(); rectangleButton = new javax.swing.JButton(); circleButton = new javax.swing.JButton(); eraseButton = new javax.swing.JButton(); textArea = new javax.swing.JTextField(); enterButton = new javax.swing.JButton(); setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE); rectangleButton.setText("Rectangle"); rectangleButton.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { rectangleButtonActionPerformed(evt); } }); circleButton.setText("Circle"); circleButton.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { circleButtonActionPerformed(evt); } }); eraseButton.setText("Erase"); eraseButton.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { eraseButtonActionPerformed(evt); } }); textArea.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { textAreaActionPerformed(evt); } }); enterButton.setText("ENTER"); enterButton.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { enterButtonActionPerformed(evt); } }); whiteEx layout = new whiteEx(getContentPane()); getContentPane().setLayout(layout); layout.setHorizontalGroup( layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING) .add(layout.createSequentialGroup() .addContainerGap() .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING) .add(layout.createSequentialGroup() .add(54, 54, 54) .add(tempLable, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 121, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE) .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED, 137, Short.MAX_VALUE) .add(rectangleButton)) .add(org.jdesktop.layout.GroupLayout.TRAILING, layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING, false) .add(org.jdesktop.layout.GroupLayout.TRAILING, eraseButton, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) .add(org.jdesktop.layout.GroupLayout.TRAILING, circleButton, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 105, Short.MAX_VALUE)) .add(layout.createSequentialGroup() .add(70, 70, 70) .add(textArea, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 254, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE) .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED) .add(enterButton))) .addContainerGap()) ); layout.setVerticalGroup( layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING) .add(layout.createSequentialGroup() .addContainerGap() .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.TRAILING) .add(tempLable, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 25, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE) .add(rectangleButton)) .addPreferredGap(org.jdesktop.layout.LayoutStyle.UNRELATED) .add(circleButton) .add(9, 9, 9) .add(eraseButton) .add(18, 18, 18) .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE) .add(enterButton) .add(textArea, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 37, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)) .addContainerGap(org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)) ); pack(); }// </editor-fold> private void rectangleButtonActionPerformed(java.awt.event.ActionEvent evt) { tempLable.setText(" Rectangle"); } private void circleButtonActionPerformed(java.awt.event.ActionEvent evt) { tempLable.setText(" Circle"); } private void eraseButtonActionPerformed(java.awt.event.ActionEvent evt) { tempLable.setText(" Earse"); } private void textAreaActionPerformed(java.awt.event.ActionEvent evt) { } private void enterButtonActionPerformed(java.awt.event.ActionEvent evt) { tempLable.setText(textArea.getText()); } /** * @param args the command line arguments */ public static void main(String args[]) { java.awt.EventQueue.invokeLater(new Runnable() { public void run() { new whiteEx().setVisible(true); } }); } // Variables declaration - do not modify private javax.swing.JButton circleButton; private javax.swing.JButton enterButton; private javax.swing.JButton eraseButton; private javax.swing.JButton rectangleButton; private javax.swing.JLabel tempLable; private javax.swing.JTextField textArea; // End of variables declaration }
- 11-16-2011, 02:57 PM #3
Re: Whiteboard GUI
First result for googling "java mouselistener": How to Write a Mouse Listener (The Java™ Tutorials > Creating a GUI With JFC/Swing > Writing Event Listeners)
How to Ask Questions the Smart Way
Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!
Similar Threads
-
"Exception in thread "Launcher:/Whiteboard" java.lang.RuntimeException: Failed to loa
By Shajith in forum EclipseReplies: 3Last Post: 03-21-2011, 01:48 PM -
whiteboard in java
By adelah in forum NetworkingReplies: 3Last Post: 09-20-2010, 03:34 PM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks