For some reason the "mousePressed" and "MouseReleased" functions are not working within the jPanel1 however the mouseDragged does work. When I click the jPanel1 i tested it, it does not even run the function...
public void jPanel1_mouseReleased(MouseEvent e) {}
public void jPanel1_mouseReleased(MouseEvent e) {}
Code:
Heres my current code....
package fp;
import java.awt.BorderLayout;
import java.awt.Dimension;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.*;
import java.awt.*;
import java.awt.event.MouseEvent;
import java.awt.event.MouseAdapter;
import javax.swing.event.MenuKeyEvent;
import javax.swing.event.MenuKeyListener;
import java.beans.PropertyChangeEvent;
import java.beans.PropertyChangeListener;
import javax.swing.border.TitledBorder;
import javax.swing.event.ChangeEvent;
import javax.swing.event.ChangeListener;
import java.awt.event.ItemEvent;
import java.awt.event.ItemListener;
import java.awt.event.MouseMotionAdapter;
import java.awt.event.MouseListener;
public class Frame1 extends JFrame{
MyMusic mm = new MyMusic();
Shape s;
int currentX, currentY, oldX, oldY;
boolean isDragging=false;
Color c;
JPanel contentPane;
JMenuBar jMenuBar1 = new JMenuBar();
JMenu jMenuFile = new JMenu();
JMenuItem jMenuFileExit = new JMenuItem();
JToolBar jToolBar1 = new JToolBar();
JButton jButton1 = new JButton();
JButton jButton3 = new JButton();
JButton jButton4 = new JButton();
JButton jButton5 = new JButton();
JButton jButton6 = new JButton();
JButton jButton7 = new JButton();
JButton jButton8 = new JButton();
ImageIcon image1 = new ImageIcon(fp.Frame1.class.getResource("selectButton.jpg"));
ImageIcon image2 = new ImageIcon(fp.Frame1.class.getResource("eraserButton.jpg"));
ImageIcon image3 = new ImageIcon(fp.Frame1.class.getResource("fillButton.jpg"));
ImageIcon image4 = new ImageIcon(fp.Frame1.class.getResource("pencilButton.jpg"));
ImageIcon image5 = new ImageIcon(fp.Frame1.class.getResource("textButton.jpg"));
ImageIcon image6 = new ImageIcon(fp.Frame1.class.getResource("lineButton.jpg"));
ImageIcon image7 = new ImageIcon(fp.Frame1.class.getResource("rectButton.jpg"));
ImageIcon image8 = new ImageIcon(fp.Frame1.class.getResource("ovalButton.jpg"));
ImageIcon image9 = new ImageIcon(fp.Frame1.class.getResource("printButton.jpg"));
ImageIcon image10 = new ImageIcon(fp.Frame1.class.getResource("saveButton.jpg"));
ImageIcon image11 = new ImageIcon(fp.Frame1.class.getResource("newButton.jpg"));
ImageIcon image12 = new ImageIcon(fp.Frame1.class.getResource("openButton.jpg"));
JMenu jMenu1 = new JMenu();
JMenuItem jMenuItem2 = new JMenuItem();
JMenuItem jMenuItem3 = new JMenuItem();
JMenuItem jMenuItem1 = new JMenuItem();
JColorChooser jColorChooser1 = new JColorChooser();
TitledBorder titledBorder1 = new TitledBorder("");
TitledBorder titledBorder2 = new TitledBorder("");
JMenuItem jMenuItem4 = new JMenuItem();
JMenuItem jMenuItem5 = new JMenuItem();
JButton jButton9 = new JButton();
JButton jButton10 = new JButton();
JMenuItem jMenuItem6 = new JMenuItem();
JButton jButton11 = new JButton();
JButton jButton12 = new JButton();
JLabel lblSelected = new JLabel();
JLabel jLabel1 = new JLabel();
JToolBar jToolBar2 = new JToolBar();
JToolBar jToolBar3 = new JToolBar();
JLabel jLabel2 = new JLabel();
JRadioButton jRadioButton1 = new JRadioButton();
JPanel jPanel1 = new JPanel();
public Frame1() {
try {
setDefaultCloseOperation(EXIT_ON_CLOSE);
jbInit();
} catch (Exception exception) {
exception.printStackTrace();
}
}
/**
* Component initialization.
*
* @throws java.lang.Exception
*/
private void jbInit() throws Exception {
contentPane = (JPanel) getContentPane();
contentPane.setLayout(null);
setSize(new Dimension(1200, 900));
setTitle("Frame Title");
jMenuFile.setText("File");
jMenuFileExit.setText("Exit");
jMenuFileExit.addActionListener(new Frame1_jMenuFileExit_ActionAdapter(this));
jMenu1.setText("Music");
jMenuItem2.setText("Stop");
jMenuItem2.addActionListener(new Frame1_jMenuItem2_actionAdapter(this));
jMenuItem2.addMouseListener(new Frame1_jMenuItem2_mouseAdapter(this));
jMenuItem3.setText("Pause");
jMenuItem3.addActionListener(new Frame1_jMenuItem3_actionAdapter(this));
jMenuItem3.addPropertyChangeListener(new
Frame1_jMenuItem3_propertyChangeAdapter(this));
jMenuItem3.addMouseListener(new Frame1_jMenuItem3_mouseAdapter(this));
jMenuItem1.setText("Play");
jMenuItem1.addActionListener(new Frame1_jMenuItem1_actionAdapter(this));
jMenuItem1.addMenuKeyListener(new Frame1_jMenuItem1_menuKeyAdapter(this));
jMenuItem1.addMouseListener(new Frame1_jMenuItem1_mouseAdapter(this));
contentPane.setAlignmentX((float) 0.5);
contentPane.setAlignmentY((float) 0.5);
contentPane.addMouseListener(new Frame1_contentPane_mouseAdapter(this));
jColorChooser1.setBorder(BorderFactory.createRaisedBevelBorder());
jColorChooser1.setDoubleBuffered(true);
jColorChooser1.setColor(Color.darkGray);
jColorChooser1.setPreviewPanel(null);
jColorChooser1.setBounds(new Rectangle( -2, 543, 1200, 356));
jColorChooser1.setBounds(new Rectangle(0, 544, 1182, 356));
jColorChooser1.addMouseListener(new Frame1_jColorChooser1_mouseAdapter(this));
jColorChooser1.addPropertyChangeListener(new
Frame1_jColorChooser1_propertyChangeAdapter(this));
jButton1.setBorder(null);
jButton1.setMaximumSize(new Dimension(26, 26));
jButton1.setMinimumSize(new Dimension(26, 26));
jButton1.setPreferredSize(new Dimension(26, 26));
jButton1.setIcon(image1);
jButton1.setText("");
jButton1.addActionListener(new Frame1_jButton1_actionAdapter(this));
jButton3.setMaximumSize(new Dimension(26, 26));
jButton3.setMinimumSize(new Dimension(26, 26));
jButton3.setPreferredSize(new Dimension(26, 26));
jButton3.setIcon(image3);
jButton3.setText("");
jButton3.addActionListener(new Frame1_jButton3_actionAdapter(this));
jButton4.setMaximumSize(new Dimension(26, 26));
jButton4.setMinimumSize(new Dimension(26, 26));
jButton4.setPreferredSize(new Dimension(26, 26));
jButton4.setIcon(image4);
jButton4.setText("");
jButton4.addActionListener(new Frame1_jButton4_actionAdapter(this));
jButton5.setMaximumSize(new Dimension(26, 26));
jButton5.setMinimumSize(new Dimension(26, 26));
jButton5.setPreferredSize(new Dimension(26, 26));
jButton5.setIcon(image5);
jButton5.setText("");
jButton5.addActionListener(new Frame1_jButton5_actionAdapter(this));
jButton6.setMaximumSize(new Dimension(26, 26));
jButton6.setMinimumSize(new Dimension(26, 26));
jButton6.setPreferredSize(new Dimension(26, 26));
jButton6.setIcon(image6);
jButton6.setText("");
jButton6.addActionListener(new Frame1_jButton6_actionAdapter(this));
jButton7.setMaximumSize(new Dimension(26, 26));
jButton7.setMinimumSize(new Dimension(26, 26));
jButton7.setPreferredSize(new Dimension(26, 26));
jButton7.setIcon(image7);
jButton7.setText("");
jButton7.addActionListener(new Frame1_jButton7_actionAdapter(this));
jButton8.setMaximumSize(new Dimension(26, 26));
jButton8.setMinimumSize(new Dimension(26, 26));
jButton8.setPreferredSize(new Dimension(26, 26));
jButton8.setIcon(image8);
jButton8.setText("");
jButton8.addActionListener(new Frame1_jButton8_actionAdapter(this));
jToolBar1.setBounds(new Rectangle( -1, 0, 306, 32));
jMenuItem4.setText("Open");
jMenuItem5.setText("Save");
jButton9.setMaximumSize(new Dimension(26, 26));
jButton9.setMinimumSize(new Dimension(26, 26));
jButton9.setPreferredSize(new Dimension(26, 26));
jButton9.setActionCommand("");
jButton9.setIcon(image9);
jButton9.setMnemonic('0');
jButton9.setText("jButton9");
jButton9.addActionListener(new Frame1_jButton9_actionAdapter(this));
jButton10.setMaximumSize(new Dimension(26, 26));
jButton10.setMinimumSize(new Dimension(26, 26));
jButton10.setPreferredSize(new Dimension(26, 26));
jButton10.setActionCommand("");
jButton10.setIcon(image10);
jButton10.setText("jButton10");
jButton10.addActionListener(new Frame1_jButton10_actionAdapter(this));
jMenuItem6.setText("Print");
jButton11.setMaximumSize(new Dimension(26, 26));
jButton11.setMinimumSize(new Dimension(26, 26));
jButton11.setPreferredSize(new Dimension(26, 26));
jButton11.setActionCommand("");
jButton11.setIcon(image11);
jButton11.setText("jButton11");
jButton11.addActionListener(new Frame1_jButton11_actionAdapter(this));
jButton12.setMaximumSize(new Dimension(26, 26));
jButton12.setMinimumSize(new Dimension(26, 26));
jButton12.setPreferredSize(new Dimension(26, 26));
jButton12.setActionCommand("");
jButton12.setIcon(image12);
jButton12.setText("jButton12");
jButton12.addActionListener(new Frame1_jButton12_actionAdapter(this));
lblSelected.setFont(new java.awt.Font("Dialog", Font.BOLD, 11));
lblSelected.setForeground(Color.red);
lblSelected.setDoubleBuffered(true);
lblSelected.setIconTextGap(50);
lblSelected.setText("");
jLabel1.setForeground(Color.red);
jLabel1.setText("Extra Options ---->");
jToolBar2.setBounds(new Rectangle(319, 0, 217, 30));
jToolBar3.setBounds(new Rectangle(535, 0, 354, 33));
jLabel2.setForeground(Color.red);
jLabel2.setText("Item Selected ----->");
jRadioButton1.setText("jRadioButton1");
jPanel1.setEnabled(true);
jPanel1.setBorder(BorderFactory.createLoweredBevelBorder());
jPanel1.setToolTipText("");
jPanel1.setBounds(new Rectangle(16, 43, 1164, 474));
jPanel1.setLayout(null);
jPanel1.addMouseMotionListener(new Frame1_jPanel1_mouseMotionAdapter(this));
jPanel1.addMouseListener(new Frame1_jPanel1_mouseAdapter(this));
jMenuBar1.add(jMenuFile);
jMenuBar1.add(jMenu1);
jMenuFile.add(jMenuItem4);
jMenuFile.add(jMenuItem5);
jMenuFile.add(jMenuItem6);
jMenuFile.add(jMenuFileExit);
setJMenuBar(jMenuBar1);
contentPane.add(jColorChooser1);
contentPane.add(jToolBar1);
jToolBar1.add(jButton11);
jToolBar1.add(jButton12);
jToolBar1.add(jButton10);
jToolBar1.add(jButton9);
jToolBar1.add(jButton1);
jToolBar1.add(jButton3);
jToolBar1.add(jButton4);
jToolBar1.add(jButton5);
jToolBar1.add(jButton6);
jToolBar1.add(jButton7);
jToolBar1.add(jButton8);
contentPane.add(jToolBar2);
contentPane.add(jToolBar3);
jToolBar2.add(jLabel1);
jToolBar2.add(jRadioButton1);
jToolBar3.add(jLabel2);
jToolBar3.add(lblSelected);
contentPane.add(jPanel1);
jMenu1.add(jMenuItem1);
jMenu1.add(jMenuItem3);
jMenu1.add(jMenuItem2);
}
/**
* File | Exit action performed.
*
* @param actionEvent ActionEvent
*/
void jMenuFileExit_actionPerformed(ActionEvent actionEvent) {
System.exit(0);
}
public void jMenuItem1_mouseReleased(MouseEvent e) {
}
public void jMenuItem1_mouseEntered(MouseEvent e) {
}
public void jMenuItem2_mouseReleased(MouseEvent e) {
}
public void jMenuItem3_propertyChange(PropertyChangeEvent evt) {
}
public void jMenuItem3_actionPerformed(ActionEvent e) {
mm.pauseMusic();
jMenuItem1.setText("Resume");
jMenuItem1.setVisible(true);
}
public void jMenuItem1_actionPerformed(ActionEvent e) {
mm.playMusic();
jMenuItem1.setVisible(false);
if(jMenuItem1.getText().equals("Resume")) jMenuItem1.setText("Play");
}
public void jMenuItem2_actionPerformed(ActionEvent e) {
mm.stopMusic();
jMenuItem1.setVisible(true);
}
public void jButton4_stateChanged(ChangeEvent e) {
}
public void jButton1_actionPerformed(ActionEvent e) {
lblSelected.setIcon(jButton1.getIcon());
}
public void jButton3_actionPerformed(ActionEvent e) {
lblSelected.setIcon(jButton3.getIcon());
}
public void jButton4_actionPerformed(ActionEvent e) {
lblSelected.setIcon(jButton4.getIcon());
}
public void jButton5_actionPerformed(ActionEvent e) {
lblSelected.setIcon(jButton5.getIcon());
}
public void jButton6_actionPerformed(ActionEvent e) {
lblSelected.setIcon(jButton6.getIcon());
}
public void jButton7_actionPerformed(ActionEvent e) {
lblSelected.setIcon(jButton7.getIcon());
}
public void jButton8_actionPerformed(ActionEvent e) {
lblSelected.setIcon(jButton8.getIcon());
s = new Circle();
}
public void jButton11_actionPerformed(ActionEvent e) {
lblSelected.setIcon(jButton11.getIcon());
}
public void jButton12_actionPerformed(ActionEvent e) {
lblSelected.setIcon(jButton12.getIcon());
}
public void jButton10_actionPerformed(ActionEvent e) {
lblSelected.setIcon(jButton10.getIcon());
}
public void jButton9_actionPerformed(ActionEvent e) {
lblSelected.setIcon(jButton9.getIcon());
}
public void jSpinner1_stateChanged(ChangeEvent e) {
}
public void jPanel1_mouseEntered(MouseEvent e) {
}
public void jPanel1_mouseReleased(MouseEvent e) {
oldX = e.getX();
oldY = e.getY();
isDragging = false;
mm.playMusic();
s.drawRegular((Graphics2D)jPanel1.getGraphics(),oldX,oldY,currentX,currentY, c);
}
public void jPanel1_mousePressed(MouseEvent e) {
isDragging = true;
mm.playMusic();
oldX = e.getX();
oldY = e.getY();
}
public void jPanel1_mouseExited(MouseEvent e) {
}
public void jPanel1_mouseDragged(MouseEvent e) {
if(isDragging)
{
currentX = e.getX();
currentY = e.getY();
s.drawRegular((Graphics2D)jPanel1.getGraphics(),oldX,oldY,currentX,currentY, c);
}
}
public void jColorChooser1_propertyChange(PropertyChangeEvent evt) {
c = jColorChooser1.getColor();
}
public void jColorChooser1_mousePressed(MouseEvent e) {
c = jColorChooser1.getColor();
}
public void jPanel1_mouseClicked(MouseEvent e) {
}
public void contentPane_mousePressed(MouseEvent e) { }
}
class Frame1_contentPane_mouseAdapter extends MouseAdapter {
private Frame1 adaptee;
Frame1_contentPane_mouseAdapter(Frame1 adaptee) {
this.adaptee = adaptee;
}
public void mousePressed(MouseEvent e) {
adaptee.contentPane_mousePressed(e);
}
}
class Frame1_jPanel1_mouseAdapter extends MouseAdapter {
private Frame1 adaptee;
Frame1_jPanel1_mouseAdapter(Frame1 adaptee) {
this.adaptee = adaptee;
}
public void mouseEntered(MouseEvent e) {
adaptee.jPanel1_mouseEntered(e);
}
}
class Frame1_jPanel1_mouseMotionAdapter extends MouseMotionAdapter {
private Frame1 adaptee;
Frame1_jPanel1_mouseMotionAdapter(Frame1 adaptee) {
this.adaptee = adaptee;
}
public void mouseDragged(MouseEvent e) {
adaptee.jPanel1_mouseDragged(e);
}
}
class Frame1_jColorChooser1_propertyChangeAdapter implements
PropertyChangeListener {
private Frame1 adaptee;
Frame1_jColorChooser1_propertyChangeAdapter(Frame1 adaptee) {
this.adaptee = adaptee;
}
public void propertyChange(PropertyChangeEvent evt) {
adaptee.jColorChooser1_propertyChange(evt);
}
}
class Frame1_jColorChooser1_mouseAdapter extends MouseAdapter {
private Frame1 adaptee;
Frame1_jColorChooser1_mouseAdapter(Frame1 adaptee) {
this.adaptee = adaptee;
}
public void mousePressed(MouseEvent e) {
adaptee.jColorChooser1_mousePressed(e);
}
}
class Frame1_jSpinner1_changeAdapter implements ChangeListener {
private Frame1 adaptee;
Frame1_jSpinner1_changeAdapter(Frame1 adaptee) {
this.adaptee = adaptee;
}
public void stateChanged(ChangeEvent e) {
adaptee.jSpinner1_stateChanged(e);
}
}
class Frame1_jButton9_actionAdapter implements ActionListener {
private Frame1 adaptee;
Frame1_jButton9_actionAdapter(Frame1 adaptee) {
this.adaptee = adaptee;
}
public void actionPerformed(ActionEvent e) {
adaptee.jButton9_actionPerformed(e);
}
}
class Frame1_jButton10_actionAdapter implements ActionListener {
private Frame1 adaptee;
Frame1_jButton10_actionAdapter(Frame1 adaptee) {
this.adaptee = adaptee;
}
public void actionPerformed(ActionEvent e) {
adaptee.jButton10_actionPerformed(e);
}
}
class Frame1_jButton12_actionAdapter implements ActionListener {
private Frame1 adaptee;
Frame1_jButton12_actionAdapter(Frame1 adaptee) {
this.adaptee = adaptee;
}
public void actionPerformed(ActionEvent e) {
adaptee.jButton12_actionPerformed(e);
}
}
class Frame1_jButton11_actionAdapter implements ActionListener {
private Frame1 adaptee;
Frame1_jButton11_actionAdapter(Frame1 adaptee) {
this.adaptee = adaptee;
}
public void actionPerformed(ActionEvent e) {
adaptee.jButton11_actionPerformed(e);
}
}
class Frame1_jButton8_actionAdapter implements ActionListener {
private Frame1 adaptee;
Frame1_jButton8_actionAdapter(Frame1 adaptee) {
this.adaptee = adaptee;
}
public void actionPerformed(ActionEvent e) {
adaptee.jButton8_actionPerformed(e);
}
}
class Frame1_jButton7_actionAdapter implements ActionListener {
private Frame1 adaptee;
Frame1_jButton7_actionAdapter(Frame1 adaptee) {
this.adaptee = adaptee;
}
public void actionPerformed(ActionEvent e) {
adaptee.jButton7_actionPerformed(e);
}
}
class Frame1_jButton6_actionAdapter implements ActionListener {
private Frame1 adaptee;
Frame1_jButton6_actionAdapter(Frame1 adaptee) {
this.adaptee = adaptee;
}
public void actionPerformed(ActionEvent e) {
adaptee.jButton6_actionPerformed(e);
}
}
class Frame1_jButton5_actionAdapter implements ActionListener {
private Frame1 adaptee;
Frame1_jButton5_actionAdapter(Frame1 adaptee) {
this.adaptee = adaptee;
}
public void actionPerformed(ActionEvent e) {
adaptee.jButton5_actionPerformed(e);
}
}
class Frame1_jButton4_actionAdapter implements ActionListener {
private Frame1 adaptee;
Frame1_jButton4_actionAdapter(Frame1 adaptee) {
this.adaptee = adaptee;
}
public void actionPerformed(ActionEvent e) {
adaptee.jButton4_actionPerformed(e);
}
}
class Frame1_jButton3_actionAdapter implements ActionListener {
private Frame1 adaptee;
Frame1_jButton3_actionAdapter(Frame1 adaptee) {
this.adaptee = adaptee;
}
public void actionPerformed(ActionEvent e) {
adaptee.jButton3_actionPerformed(e);
}
}
class Frame1_jButton1_actionAdapter implements ActionListener {
private Frame1 adaptee;
Frame1_jButton1_actionAdapter(Frame1 adaptee) {
this.adaptee = adaptee;
}
public void actionPerformed(ActionEvent e) {
adaptee.jButton1_actionPerformed(e);
}
}
class Frame1_jMenuItem1_mouseAdapter extends MouseAdapter {
private Frame1 adaptee;
Frame1_jMenuItem1_mouseAdapter(Frame1 adaptee) {
this.adaptee = adaptee;
}
public void mouseReleased(MouseEvent e) {
adaptee.jMenuItem1_mouseReleased(e);
}
}
class Frame1_jMenuItem1_menuKeyAdapter implements MenuKeyListener {
private Frame1 adaptee;
Frame1_jMenuItem1_menuKeyAdapter(Frame1 adaptee) {
this.adaptee = adaptee;
}
public void menuKeyTyped(MenuKeyEvent e) {
}
public void menuKeyPressed(MenuKeyEvent e) {
}
public void menuKeyReleased(MenuKeyEvent e) { }
}
class Frame1_jMenuItem2_mouseAdapter extends MouseAdapter {
private Frame1 adaptee;
Frame1_jMenuItem2_mouseAdapter(Frame1 adaptee) {
this.adaptee = adaptee;
}
public void mouseReleased(MouseEvent e) {
adaptee.jMenuItem2_mouseReleased(e);
}
}
class Frame1_jMenuItem2_actionAdapter implements ActionListener {
private Frame1 adaptee;
Frame1_jMenuItem2_actionAdapter(Frame1 adaptee) {
this.adaptee = adaptee;
}
public void actionPerformed(ActionEvent e) {
adaptee.jMenuItem2_actionPerformed(e);
}
}
class Frame1_jMenuItem3_mouseAdapter extends MouseAdapter {
private Frame1 adaptee;
Frame1_jMenuItem3_mouseAdapter(Frame1 adaptee) {
this.adaptee = adaptee;
}
public void mousePressed(MouseEvent e) {
}
}
class Frame1_jMenuItem3_propertyChangeAdapter implements PropertyChangeListener {
private Frame1 adaptee;
Frame1_jMenuItem3_propertyChangeAdapter(Frame1 adaptee) {
this.adaptee = adaptee;
}
public void propertyChange(PropertyChangeEvent evt) {
adaptee.jMenuItem3_propertyChange(evt);
}
}
class Frame1_jMenuItem3_actionAdapter implements ActionListener {
private Frame1 adaptee;
Frame1_jMenuItem3_actionAdapter(Frame1 adaptee) {
this.adaptee = adaptee;
}
public void actionPerformed(ActionEvent e) {
adaptee.jMenuItem3_actionPerformed(e);
}
}
class Frame1_jMenuItem1_actionAdapter implements ActionListener {
private Frame1 adaptee;
Frame1_jMenuItem1_actionAdapter(Frame1 adaptee) {
this.adaptee = adaptee;
}
public void actionPerformed(ActionEvent e) {
adaptee.jMenuItem1_actionPerformed(e);
}
}
class Frame1_jMenuFileExit_ActionAdapter implements ActionListener {
Frame1 adaptee;
Frame1_jMenuFileExit_ActionAdapter(Frame1 adaptee) {
this.adaptee = adaptee;
}
public void actionPerformed(ActionEvent actionEvent) {
adaptee.jMenuFileExit_actionPerformed(actionEvent);
}
}