package cs3744; import cs3744.gui.VTButton; import cs3744.gui.VTColor; import cs3744.gui.VTFrame; import cs3744.gui.VTGridLayout; import cs3744.gui.VTLabel; import cs3744.gui.VTPanel; import cs3744.gui.event.VTActionAdapter; import cs3744.gui.event.VTActionEvent; /** * @author Denis Gracanin * @version 1.0 */ public class HomeworkFive extends VTFrame { private VTLabel label1, label2; private VTPanel panel2; private boolean state; public HomeworkFive(String title) { super(title); initComponents(); state = true; } private void initComponents() { VTPanel panel1 = new VTPanel(); panel1.setLayout(new VTGridLayout(2, 1)); VTButton button = new VTButton("Click Me!"); button.addVTActionListener(new VTActionAdapter() { @Override public void actionPerformed(VTActionEvent e) { if (state) { label1.setText("It Works!"); label1.setAlignment(VTLabel.Alignment.CENTER); label1.setBackground(VTColor.PINK); label1.setForeground(VTColor.BLUE); panel2.remove(label2); panel2.setLayout(new VTGridLayout(1, 1)); } else { label1.setText("It Still Works!"); label1.setAlignment(VTLabel.Alignment.RIGHT); label1.setBackground(VTColor.BLUE); label1.setForeground(VTColor.PINK); label2.setAlignment(VTLabel.Alignment.LEFT); label2.setBackground(VTColor.WHITE); label2.setForeground(VTColor.CYAN); panel2.add(label2); panel2.setLayout(new VTGridLayout(2, 1)); } state = !state; } }); button.setBackground(VTColor.GREEN); button.setForeground(VTColor.RED); panel1.add(button); panel2 = new VTPanel(); panel2.setLayout(new VTGridLayout(1, 2)); label1 = new VTLabel("Second", VTLabel.Alignment.LEFT); label1.setBackground(VTColor.BLUE); label1.setForeground(VTColor.YELLOW); panel2.add(label1); label2 = new VTLabel("Third", VTLabel.Alignment.RIGHT); label2.setBackground(VTColor.MAGENTA); label2.setForeground(VTColor.ORANGE); panel2.add(label2); panel1.add(panel2); getContentPane().add(panel1); } public static void main(String[] args) { HomeworkFive hw5 = new HomeworkFive("Homework Five"); hw5.pack(); hw5.setSize(400, 400); hw5.setVisible(true); } }