im writing a drawing program in java, and i ran into some problems
.. i got 2 files..a frame file..and a file with all the other stuff(buttons , colorpickers, drawing methods. etc..)
but i cant get the buttons to display.
the only thing im getting is the drawing panel
anyways heres my code.
import javax.swing.JPanel;
import java.awt.*;
import javax.swing.*;
import java.awt.event.*;
import java.util.ArrayList;
public class DrawPanel extends JPanel
{
private Point p1= null, p2= null;
private ArrayList lineP1 = new ArrayList(), lineP2 = new ArrayList();
private int x;
private String drawWhat;
private JPanel left = new JPanel();
private JLabel leftside = new JLabel();
public DrawPanel()
{
DrawListener listener = new DrawListener();
addMouseListener(listener);
addMouseMotionListener(listener);
setBackground(Color.white);
setPreferredSize(new Dimension(800,600));
JButton BLine = new JButton("line");
JButton BRect = new JButton("rect");
leftside.add(BLine);
leftside.add(BRect);
left.add(leftside);
}
public void paintComponent(Graphics page)
{
super.paintComponent(page);
page.setColor (Color.black);
//while()
//while(lineP1.get(x) != null && lineP2.get(x) != null)
//{
for(x = 0; x < lineP2.size(); ++x)
{
page.drawLine(((Point)lineP1.get(x)).x,((Point)lin eP1.get(x)).y,((Point)lineP2.get(x)).x,((Point)lin eP2.get(x)).y);
}
//}
}
private class DrawListener implements MouseListener, MouseMotionListener
{
public void mousePressed(MouseEvent event)
{
p1 = event.getPoint();
}
public void mouseDragged(MouseEvent event)
{
p2 = event.getPoint();
}
public void mouseClicked(MouseEvent event){}
public void mouseReleased(MouseEvent event)
{
lineP1.add(p1);
lineP2.add(p2);
repaint();
}
public void mouseEntered(MouseEvent event){}
public void mouseExited(MouseEvent event){}
public void mouseMoved(MouseEvent event){}
}
private class LineListener implements ActionListener
{
public void actionPerformed(ActionEvent event)
{
drawWhat = "line";
}
}
}