package paint;
import java.awt.event.*;
import java.awt.*;
import javax.swing.*;
/**
* @author Administrator
*
*/
public class Tools extends JPanel implements ActionListener{
static Color color;
FlowLayout layout=new FlowLayout( );
//private JButton[] jButtons= new JButton[8];
private JButton lineLabel ;
private JButton rectLabel ;
private JButton polyLabel ;
private JButton ovalLabel ;
private JButton rrectLabel;
private JButton textLabel ;
private JButton penLabel;
private JButton brushLabel;
//private Icon[] iCons=new Icon[8];
Icon lineBug = new ImageIcon( getClass().getResource( "image/bug1.JPG" ) );
Icon rectBug = new ImageIcon( getClass().getResource( "image/bug2.JPG" ) );
Icon polyBug = new ImageIcon( getClass().getResource( "image/bug3.JPG" ) );
Icon ovalBug = new ImageIcon( getClass().getResource( "image/bug4.JPG" ) );
Icon rrectBug = new ImageIcon( getClass().getResource( "image/bug5.JPG") );
Icon textBug = new ImageIcon( getClass().getResource( "image/bug6.JPG" ) );
Icon brushBug = new ImageIcon(getClass().getResource( "image/bug7.JPG" ));
Icon penBug = new ImageIcon(getClass().getResource( "image/bug8.JPG" ));
/*for(int i=0;i<iCons.length;i++){
iCons[i]=new ImageIcon( getClass().getResource( "image/bug"+(i+1)+".JPG" ) );
}*/
private Dimension dem = new Dimension(lineBug.getIconWidth(),lineBug.getIconHeight());
Icon emBug = new ImageIcon(getClass().getResource( "image/embug.JPG" ));
Icon emrBug = new ImageIcon(getClass().getResource( "image/emrbug.JPG" ));
Icon fullBug = new ImageIcon(getClass().getResource( "image/fullbug.JPG" ));
private JButton emLabel = new JButton(emBug);
private JButton emrLabel= new JButton(emrBug);
private JButton fullLabel = new JButton(fullBug);
public Tools(){
setLayout( layout );
setBackground( Color.WHITE);
setBounds(0,4,61,500);
penLabel = new JButton(penBug);
penLabel.setPreferredSize(dem);
add(penLabel);
penLabel.setVisible(true);
brushLabel = new JButton(brushBug);
brushLabel.setPreferredSize(dem);
add(brushLabel);
brushLabel.setVisible(true);
lineLabel= new JButton(lineBug);
lineLabel.setPreferredSize(dem);
add(lineLabel);
lineLabel.setVisible(true);
rectLabel= new JButton(rectBug);
rectLabel.setPreferredSize(dem);
add(rectLabel);
rectLabel.addActionListener(this);
rectLabel.setVisible(true);
polyLabel= new JButton(polyBug);
polyLabel.setPreferredSize(dem);
add(polyLabel);
polyLabel.addActionListener(this);
polyLabel.setVisible(true);
ovalLabel = new JButton();
ovalLabel.setIcon(ovalBug);
ovalLabel.setPreferredSize(dem);
add(ovalLabel);
ovalLabel.addActionListener(this);
ovalLabel.setVisible(true);
rrectLabel= new JButton(rrectBug);
rrectLabel.setPreferredSize(dem);
add(rrectLabel);
rrectLabel.addActionListener(this);
rrectLabel.setVisible(true);
textLabel= new JButton(textBug);
textLabel.setPreferredSize(dem);
add(textLabel);
textLabel.setVisible(true);
/*for(int i=0;i<jButtons.length;i++){
jButtons[i]=new JButton(iCons[i]);
jButtons[i].setPreferredSize(dem);
add(jButtons[i]);
jButtons[i].addActionListener(this);
}*/
emrLabel.addActionListener(this);
emLabel.addActionListener(this);
fullLabel.addActionListener(this);
}
public void actionPerformed(ActionEvent e){
Object o = e.getSource();
if(o == lineLabel){
我想在这里把添加的Label去掉。。
remove(emLabel);
remove(emrLabel);
remove(fullLabel);//这个移除不了。。。
validate();
}
else if(o == rectLabel){
add(emLabel);
add(emrLabel);
add(fullLabel);
validate();
}
else if(o ==polyLabel){
add(emLabel);
add(emrLabel);
add(fullLabel);
validate();
}
else if(o == ovalLabel){
//handle.getDrawJpanel().setLineTag(true);
add(emLabel);
add(emrLabel);
add(fullLabel);
validate();
}
else if(o == rrectLabel){
add(emLabel);
add(emrLabel);
add(fullLabel);
validate();
}
else if(o == textLabel){
}
else if(o==penLabel){
//handle.getremove()
}
else if(o==emLabel){
}
else if(o==emrLabel){
}
else if(o== fullLabel){
}
}
}
[此贴子已经被作者于2007-6-16 11:28:31编辑过]