Computer Forums

Member Login

Remember Me? Sign Up! | Forgot Password
 
Slogan
 
Closed Thread
Old 12-03-2005, 11:08 AM   #1 (permalink)
ibexpiotr's Avatar
 
True Techie

Join Date: Nov 2003

Posts: 197

ibexpiotr is on a distinguished road

Send a message via AIM to ibexpiotr
Default drawing program java

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";

}
}
}
ibexpiotr is offline  
 
Closed Thread

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On