-
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.
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
}
-
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.
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
}
-
Re: Whiteboard GUI