Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package awtHomework4;
- import java.awt.*;
- import java.awt.event.*;
- public class AWTHomework4 extends Frame implements ActionListener {
- CheckboxGroup grp1 = new CheckboxGroup();
- CheckboxGroup grp2 = new CheckboxGroup();
- Checkbox ascending = new Checkbox("Ascending", grp1, true);
- Checkbox descending = new Checkbox("Descending", grp1, false);
- Checkbox s1 = new Checkbox("Step 1", grp2, true);
- Checkbox s5 = new Checkbox("Step 5", grp2, false);
- Checkbox s10 = new Checkbox("Step 10", grp2, false);
- int res = 0;
- Label result = new Label( ""+res, Label.RIGHT);
- Button clickMe = new Button("ClickMe!");
- Button clear = new Button("Clear!");
- Panel west = new Panel(new GridLayout(0,1));
- Panel center = new Panel();
- Panel east = new Panel(new GridLayout(0,1));
- public AWTHomework4() {
- west.add( ascending);
- west.add( descending);
- west.add(new Label());
- west.add( s1);
- west.add( s5);
- west.add( s10);
- clickMe.addActionListener(this);
- clear.addActionListener(this);
- east.add( clickMe);
- east.add( result);
- east.add( clear);
- this.add( west, BorderLayout.WEST);
- this.add( center, BorderLayout.CENTER);
- this.add( east, BorderLayout.EAST);
- this.setTitle("ButtonCounterDemo");
- this.setSize(300, 150);
- this.setVisible(true);
- this.addWindowListener(new ExitProgram());
- }
- public void actionPerformed(ActionEvent e) {
- Button x = (Button)e.getSource();
- if(x.equals(clickMe)) {
- if(s1.getState()) {
- if(ascending.getState()) res += 1;
- else res -= 1;
- result.setText( ""+res );
- }
- if(s5.getState()) {
- if(ascending.getState()) res += 5;
- else res -= 5;
- result.setText( ""+res );
- }
- if(s10.getState()) {
- if(ascending.getState()) res += 10;
- else res -= 10;
- result.setText( ""+res );
- }
- }
- if(x.equals(clear)) {
- res = 0;
- result.setText( ""+res);
- }
- }
- public static void main(String [] args) {
- new AWTHomework4();
- }
- }
- class ExitProgram extends WindowAdapter {
- public void windowClosing( WindowEvent e ) {
- System.exit(0);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment