The given Java program is called the ColorDialog. When running, the ColorDialog has a menubar and 25 ColorButtons arranged in a 5x5 gird. Each of the 25 ColorButtons has a background color and a label. The ColorButtons have a set of ColorLabel objects to keep track of its current color. The starting values of the 25 ColorButtons are “RED” and the color is, of course, red. When a ColorButton is clicked with a mouse, its color and label move to the next color in a sequence. The sequence is RED, ORANGE, YELLOW, GREEN, BLUE, INDIGO and VIOLET. The menubar menu has two items: Reset and Save. Reset puts all the ColorButtons back to RED. The Save menu item...well, does nothing. This is the task to be built for this assignment. The ColorDialog has an associated ColorDialogRecord. When the ColorDialog Save menu item is selected, Copy the information of the ColorDialog into the ColorDialogRecord o The ColorDialogRecord will need a 5x5 array of strings, and a filename. o Copy the current string from color label from the ColorDialog and its components into ColorDialogRecord. Use getters and setters as needed. o Create a SAVE member function for ColorDialogRecord and have the save to file done in that Class. o Save the row, the column, and the color in the file, with one set of button information per line.
package colordialog;
import java.awt.Color;
import java.awt.Graphics;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.GradientPaint;
import javax.swing.JButton;
class ColorButton extends JButton implements ActionListener
{
int indexColor;
ColorLabel currColor;
ColorLabel [] colorArray;
ColorButton()
{
colorArray=new ColorLabel[7];
colorArray[0]=new ColorLabel("RED" ,new Color(255, 0, 0));//RED
colorArray[1]=new ColorLabel("ORANGE",new Color(255,128, 0));//ORANGE
colorArray[2]=new ColorLabel("YELLOW",new Color(255,255, 0));//YELLOW
colorArray[3]=new ColorLabel("GREEN" ,new Color( 0,255, 0));//GREEN
colorArray[4]=new ColorLabel("BLUE" ,new Color( 0, 0,255));//Blue
colorArray[5]=new ColorLabel("INDIGO",new Color(128, 0,255));//INDIGO
colorArray[6]=new ColorLabel("VIOLET",new Color(192, 0,192));//PURPLE
indexColor=0;
currColor=colorArray[indexColor];
setSize(50,50);
this.setForeground(Color.black);
this.setText(currColor.getLabel());
this.setBackground(currColor.getColor());
this.addActionListener(this);
}
@Override
public void actionPerformed(ActionEvent ae) {
indexColor=(indexColor+1)%7;
currColor=colorArray[indexColor];
invalidate();
}
@Override
public void paint(Graphics g)
{
float x1=0.0f;
float y1=0.0f;
Color color1=Color.white;
float x2=0.0f;
float y2=0.0f;
Color color2=Color.black;
java.awt.GradientPaint gp=new GradientPaint(x1,y1,color1,x2,y2,color2);
this.setBackground(currColor.getColor());
this.setText(currColor.getLabel());
super.paint(g);
}
public String getColor()
{
return currColor.getLabel();
}
public void reset()
{
indexColor=0;
currColor=colorArray[indexColor];
invalidate();
}
}
The given Java program is called the ColorDialog. When running, the ColorDialog has a menubar and 25 ColorButtons arranged in a 5x5 gird.
Each of the 25 ColorButtons has a background color and a label. The ColorButtons have a set of ColorLabel objects to keep track of its current color. The starting values of the 25 ColorButtons are “RED” and the color is, of course, red. When a ColorButton is clicked with a mouse, its color and label move to the next color in a sequence. The sequence is RED, ORANGE, YELLOW, GREEN, BLUE, INDIGO and VIOLET.
The menubar menu has two items: Reset and Save. Reset puts all the ColorButtons back to RED. The Save menu item...well, does nothing. This is the task to be built for this assignment.
The ColorDialog has an associated ColorDialogRecord.
- When the ColorDialog Save menu item is selected,
- Copy the information of the ColorDialog into the ColorDialogRecord
o The ColorDialogRecord will need a 5x5 array of strings, and a filename.
o Copy the current string from color label from the ColorDialog and its components into ColorDialogRecord. Use getters and setters as needed.
o Create a SAVE member function for ColorDialogRecord and have the save to file done in that Class.
o Save the row, the column, and the color in the file, with one set of button information per line.
Trending now
This is a popular solution!
Step by step
Solved in 2 steps with 2 images