import java.awt.*; import java.awt.event.*; import javax.swing ...

slimwhimperSoftware and s/w Development

Nov 3, 2013 (3 years and 10 months ago)

63 views

import

java.awt.*;

import

java.awt.event.*;

import

javax.swing.*;

public

class

A1

extends

JFrame{


JButton
b
[] =
new

JButton[3];


int

ct
[] =
new

int
[3];


JTextField
tf

=
new

JTextField(
"b1"
,30);


A1(){



setLayout(
new

FlowLayout());



setBounds(20,20,400,300);



setVisible(
true
);



setDefaultCloseOperation(JFrame.
EXIT_ON_CLOSE
);



for
(
int

i = 0; i<3;i++){




b
[i] =
new

JButton(
"b"
+i);




add(
b
[i]);




b
[i].addActionListener(
new

Cl());



}



add (
tf
);



}


class

Cl
implements

ActionListener{



public

void

actionPerformed(ActionEvent e){




int

n= e.getActionCommand().charAt(1)
-
'0'
;




ct
[n]++;




tf
.setText(
"b0:"
+
ct
[0]+
" b1:"
+
ct
[1]+
" b2:"
+
ct
[2]);



}


}


public

static

void

main(String [] arg){



A1
a1

=
new

A1();




}

}


import

java.awt
.*;

import

java.awt.event.*;

import

javax.swing.*;

public

class

A2

extends

A1{


JButton
bm

=
new

JButton(
"max"
);


A2(){



add(
bm
);



bm
.addActionListener(
new

Bm());




}


class

Bm
implements

ActionListener{



public

void

actionPerformed(ActionEvent e){




int

i,n,max;




for

(i=n=0,max=
ct
[0];i<3;i++)





if
(max<
ct
[i]){






max=
ct
[i]; n=i;





}




tf
.setText(
"b"
+n+
":"
+max);



}


}


public

static

void

main(String [] arg){



A2
a2

=
new

A2();




}

}