derLayout.CENTER );
buttonPanel=new JPanel () ;. setBackground (Color.white) ;. setLayout (new FlowLayout ());
redButton=new JButton ( More Red ) ;. setBackground (Color.red) ;. addActionListener (this) ;. add (redButton); greenButton=new JButton ( More Green ) ;. setBackground (Color.green) ;. addActionListener (this) ;. add (greenButton);
blueButton=new JButton ( More Blue ) ;. setBackground (Color.blue) ;. addActionListener (this) ;. add (blueButton) ;. add (buttonPanel, BorderLayout.SOUTH);
}
void actionPerformed (ActionEvent e)
{actionCommand=e.getActionCommand ();
(actionCommand.equals ( More Red ))
{(redValue lt;=250)=redValue + 5;
} if (actionCommand.equals ( More Green ))
{(greenValue lt;=250)=greenValue + 5;
} if (actionCommand.equals ( More Blue ))
{(blueValue lt;=250)=blueValue + 5;
}. out.println ( Unexplained Error );
=new Color (redValue, greenValue, blueValue) ;. setBackground (panelColor);
}
}
Додаток 8
javax.swing. *; java.awt. *; java.awt.event. *;
class VisibilityDemoExercise extends JFrameActionListener
{static final int WIDTH=300; static final int HEIGHT=200;
JLabel upLabel; JLabel downLabel; JButton upButton; JButton downButton;
VisibilityDemoExercise ()
{(WIDTH, HEIGHT); (new WindowDestroyer ()); ( Visibility Demonstration ); contentPane=getContentPane () ;. setLayout (new BorderLayout ()) ;. setBackground (Color. white);
=new JLabel ( Here I am up here! ) ;. add (upLabel, BorderLayout.NORTH) ;. setVisible (false);=new JLabel ( Here I am down here! ) ;. add (downLabel, BorderLayout.SOUTH) ;. setVisible (false);
buttonPanel=new JPanel () ;. setBackground (Color.white) ;. setLayout (new FlowLayout ());=new JButton ( Up ) ;. addActionListener (this) ;. add (upButton);=new JButton ( Down ) ;. addActionListener (this) ;. add (downButton) ;. add (buttonPanel, BorderLayout.CENTER);
}
void actionPerformed (ActionEvent e)
{(e.getActionCommand (). equals ( Up ))
{. setVisible (true) ;. setVisible (false) ;. setVisible (false) ;. setVisible (true); ();
} if (e.getActionCommand (). equals ( Down ))
{. setVisible (true) ;. setVisible (false) ;. setVisible (false) ;. setVisible (true); ();
}. out.println (
Error in VisibilityDemoExercise interface. );
}
static void main (String [] args)
{demoGui=new VisibilityDemoExercise () ;. setVisible (true);
}
}
Додаток 9
javax.swing. *; java.awt. *; java.awt.event. *;
class CardLayoutDemo extends JFrame implements ActionListener
{static final int WIDTH=300; static final int HEIGHT=200;
CardLayout dealer; JPanel deckPanel;
CardLayoutDemo ()
{(WIDTH, HEIGHT); (new WindowDestroyer ()); ( CardLayout Demonstration ); contentPane=getContentPane () ;. setLayout (new BorderLayout ());
=new JPanel ();=new CardLayout () ;. setLayout (dealer);
startCardPanel=new JPanel () ;. setLayout (new FlowLayout ()) ;. setBackground (Color.lightGray); startLabel=new JLabel ( Hello ) ;. add (startLabel) ;. add ( start raquo ;, startCardPanel);
greenCardPanel=new JPanel () ;. setLayout (new FlowLayout ()) ;. setBackground (Color.green); goLabel=new JLabel ( Go ) ;. add (goLabel) ;. add ( green raquo ;, greenCardPanel);
yellowCardPanel=new JPanel () ;. setLayout (new FlowLayout ()) ;. setBackground (Color.yellow); prepareLabel=new JLabel ( Prepare ) ;. add (prepareLabel) ;. add ( yellow raquo ;, yellowCardPanel);
redCardPanel=new JPanel () ;. setLayout (new FlowLayout ()) ;. setBackground (Color.red); redLabel=new JLabel ( Stop ) ;. add (redLabel) ;. add ( red raquo ;, redCardPanel);
. add (deckPanel, BorderLayout.CENTER);
buttonPanel=new JPanel () ;. setBackground (Color.white) ;. setLayout (new FlowLayout ()); stopButton=n...