Open color dialog box in applet java code
How to open color dialog box in applet java code.
public class ColorDialog extends Dialog
{
public ColorDialog(Frame p)
{
super(p, "Color Dialog", true);
OK_button = new Button("OK");
Cancel_button = new Button("Cancel");
OK_Cancel = new Panel();
init();
show();
}
public ColorDialog(Frame p, Color c)
{
super(p, "Color Dialog", true);
OK_button = new Button("OK");
Cancel_button = new Button("Cancel");
OK_Cancel = new Panel();
init();
color_panel.setCurColor(c);
show();
}
private void init()
{
setResizable(false);
setLayout(null);
color_panel = new ColorPanel();
color_panel.setLocation(0, 0);
add(color_panel);
Dimension d = color_panel.getSize();
int cp_x = d.width;
int cp_y = d.height;
OK_Cancel.setLayout(new GridLayout(1, 2, 5, 5));
OK_Cancel.add(OK_button);
OK_Cancel.add(Cancel_button);
OK_Cancel.setBounds(20, cp_y + 20, 100, 20);
add(OK_Cancel);
setSize(cp_x, cp_y + 100);
}
public boolean handleEvent(Event event)
{
if(event.target == OK_button && event.id == 1001)
{
OKButton_Clicked(event);
return true;
}
if(event.target == Cancel_button && event.id == 1001)
{
CancelButton_Clicked(event);
return true;
}
if(event.target == this && event.id == 201)
{
dispose();
return true;
} else
{
return super.handleEvent(event);
}
}
public void CancelButton_Clicked(Event event)
{
isOK = false;
dispose();
}
public void OKButton_Clicked(Event event)
{
color = color_panel.curcolor;
isOK = true;
dispose();
}
public ColorPanel color_panel;
private Button OK_button;
private Button Cancel_button;
private Panel OK_Cancel;
public boolean isOK;
public Color color;
}
public class ColorDialog extends Dialog
{
public ColorDialog(Frame p)
{
super(p, "Color Dialog", true);
OK_button = new Button("OK");
Cancel_button = new Button("Cancel");
OK_Cancel = new Panel();
init();
show();
}
public ColorDialog(Frame p, Color c)
{
super(p, "Color Dialog", true);
OK_button = new Button("OK");
Cancel_button = new Button("Cancel");
OK_Cancel = new Panel();
init();
color_panel.setCurColor(c);
show();
}
private void init()
{
setResizable(false);
setLayout(null);
color_panel = new ColorPanel();
color_panel.setLocation(0, 0);
add(color_panel);
Dimension d = color_panel.getSize();
int cp_x = d.width;
int cp_y = d.height;
OK_Cancel.setLayout(new GridLayout(1, 2, 5, 5));
OK_Cancel.add(OK_button);
OK_Cancel.add(Cancel_button);
OK_Cancel.setBounds(20, cp_y + 20, 100, 20);
add(OK_Cancel);
setSize(cp_x, cp_y + 100);
}
public boolean handleEvent(Event event)
{
if(event.target == OK_button && event.id == 1001)
{
OKButton_Clicked(event);
return true;
}
if(event.target == Cancel_button && event.id == 1001)
{
CancelButton_Clicked(event);
return true;
}
if(event.target == this && event.id == 201)
{
dispose();
return true;
} else
{
return super.handleEvent(event);
}
}
public void CancelButton_Clicked(Event event)
{
isOK = false;
dispose();
}
public void OKButton_Clicked(Event event)
{
color = color_panel.curcolor;
isOK = true;
dispose();
}
public ColorPanel color_panel;
private Button OK_button;
private Button Cancel_button;
private Panel OK_Cancel;
public boolean isOK;
public Color color;
}
Comments
Post a Comment