Hei currently working on an program that shall draw different shapes selected from a JComboBox. I cant seem to get the MouseListener/ComboBox to understand which shapes i selecet. Here is what i got so far in the GUI window..all the other files seems to be correct..Shapes.java, Circle.java , section.java , segment. java....and so on..
class DrawingWindow extends JFrame implements MouseListener, MouseMotionListener,ActionListener,ItemListener { private String[] shapes= { "section", "segment", "square", "Rect" , "Circle", "Ellipse" }; private drawingPanel drawingPad; private JPanel ButtonPanel; private JComboBox box = new JComboBox(figurer); private JButton knapp = new JButton("Tegn"); private Shape shapes; public TegneVindu(String title) { this.setTitle(tittel); this.setSize( 600, 600 ); this.setDefaultCloseOperation(EXIT_ON_CLOSE); JPanel np = new JPanel (); add(np, BorderLayout.NORTH); JLabel textfield= new JLabel("Choose shape of the figure: "); np.add(textfield); np.add(box); box.addItemListener(this); JPanel sp = new JPanel(new BorderLayout()); add(sp, BorderLayout.CENTER); drawingPad = new drawingPanel( ); drawingPad.addMouseListener(this); drawingPad.addMouseMotionListener(this); sp.add(drawingPad); sp.add(knapp, BorderLayout.NORTH); knapp.addActionListener(this); } @Override public void mouseClicked(MouseEvent e) { } @Override public void mousePressed(MouseEvent e) { shapes= new segment(Color.black, e.getX(), e.getY(), e.getX(), e.getY() ); drawingPad.setFigur(figuren); drawingPad.repaint(); } @Override public void itemStateChanged(ItemEvent evt) { if (evt.getStateChange() == ItemEvent.SELECTED) { ???????????????????????? code here ???????????++ } } @Override public void mouseReleased(MouseEvent e) { shapes.changeSize(e.getX(), e.getY() ); drawingPad.repaint(); } @Override public void mouseDragged(MouseEvent e) { shapes.changeSize(e.getX(), e.getY() ); drawingPad.repaint(); } @Override public void mouseEntered(MouseEvent e) { } @Override public void mouseExited(MouseEvent e) { } @Override public void mouseMoved(MouseEvent e) { } @Override public void actionPerformed(ActionEvent e) { } }