import java.awt.*;
import javax.swing.*;
import java.awt.event.*;
import java.io.File;
import java.io.IOException;
public class colorchooser extends JApplet implements ActionListener
{ JFileChooser ch=new JFileChooser();
JPanel jpanel=new JPanel();
JButton jbutton,b2;
JTextField txt;
public void init()
{ txt=new JTextField(20);
jbutton=new JButton("Click here to change colors.");
b2=new JButton("Click here to openBox");
b2.addActionListener(this);
b2.setToolTipText("This is a button to go opendialogBox");
jbutton.setToolTipText("This is a button to go colorDialog");
jbutton.addActionListener(this);
jpanel.add(jbutton);
jpanel.add(b2);
jpanel.add(txt);
getContentPane().add(jpanel);
}
public void actionPerformed(ActionEvent e)
{
if(e.getSource()==jbutton){
Runtime r=Runtime.getRuntime();
Process p=null;
Color color=JColorChooser.showDialog(colorchooser.this,"Select a new color...",Color.orange);
try {
p=r.exec("notepad.exe");
} catch (IOException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
jpanel.setBackground(color);}
if(e.getSource()==b2){
ch.showOpenDialog(this);
File f=ch.getSelectedFile();
txt.setText(f.toString());
txt.setBackground(Color.red);}
}
public void showStatus(String f){
}
}
No comments:
Post a Comment