Joke Collection Website - Blessing messages - Help modify a simple java program
Help modify a simple java program
Import java.awt.button;
Import java.awt.cardlayout;
Import java.awt.color;
Import java.awt.frame;
Import java.awt.gridlayout;
Import java.awt.label;
Import java.awt.panel;
Import java.awt.textfield;
Import java.awt.event.actionevent;
Import java.awt.event.actionlistener;
Import java.awt.event.keyevent;
Import java.awt.event.keylistener;
Import java.awt.event.windowadapter;
Import java.awt.event.windowevent;
Import java.util.hashtable;
Common class framework {
Frame f = new frame ("fancy grocery store");
Panel p = new Panel();
Panel p 1 = new Panel();
Panel p2 = new Panel();
Panel p3 = new panel ();
Label cost label = new label ("cost");
Label massLabel = new label ("quality");
TextField cost TextField = new TextField();
TextField mass TextField = new TextField();
Button lemonsButton = new Button ("lemon");
Button orangesButton = new Button ("orange");
Button Strawbery Button = new Button(" Strawbery ");
Button Pears Button = new Button(" Pears ");
Button Apples Button = new Button(" apple ");
Button peachesButton = new Button ("peach");
Button Avocados Button = new Button(" Avocados ");
Button bananasButton = new Button ("banana");
Button Cherry Button = new Button(" Cherry ");
Button BT 10 = New button ("");
Button BT 1 1 = New button ("");
Button BT 12 = New button ("");
Button WEIGHT Button = new Button(" WEIGHT ");
Button PRINT Button = new Button(" PRINT ");
Button closeButton = new button ("close");
Button[] BT = { lemonsButton,orangesButton,strawberyButton,pearsButton,
Apple button, peach button, avocado button, banana button,
CherryButton, BT 10, BT 1 1, BT 12, weight button, print button,
close button };
Private double costDouble
Common Framework () {
f . set layout(new card layout());
f.add(p," "); // +++++
CostLabel.setAlignment (label. Right);
MassLabel.setAlignment (label. Left);
cost textfield . set editable(false);
//cost textfield . addactionlistener(new textfield());
cost textfield . settext(" 0 ");
mass textfield . set editable(false);
//mass textfield . addactionlistener(new textfield());
mass textfield . addkey listener(new verifyiputkeyadapter());
mass textfield . settext(" 0 ");
p . set layout(new BorderLayout());
p.add(p 1,BorderLayout。 Center);
p.add(p2,BorderLayout。 North);
p.add(p3,BorderLayout。 South);
p 1 . set background(color . blue);
p 1 . set layout(new GridLayout(5,3));
p2 . set layout(new GridLayout());
p2 . add(cost label);
p2 . add(cost textfield);
P3 . set layout(new GridLayout());
P3 . add(mass textfield);
P3 . add(mass label);
for(int I = 0; I< 15; i++) {
p 1 . add(BT[I]);
}
for(int j = 0; j & lt9; j++) {
BT[j]。 addActionListener(new button());
}
BT[9]。 addActionListener(new blank());
BT[ 10]。 addActionListener(new blank());
BT[ 1 1]。 addActionListener(new blank());
BT[ 12]。 addActionListener(new weight());
BT[ 13]。 addActionListener(new print());
BT[ 14]。 addActionListener(new close());
f.setSize(450,280);
f . setresizable(false);
f . set visible(true);
f . addwindowlistener(new window adapter(){
public void window closing(window event e){
system . exit( 1);
}
});
}
Public static void main(String[] args) {
Frame frame = newframe ();
}
Class buttons implement ActionListener {
public void action performed(action event e){
Price p0 = new price ();
Double d =(Double)P0 . ht . get(e . getactioncommand());
//system . out . println(d . tostring());
cost textfield . settext(d . tostring());
mass textfield . set editable(false);
cost double = d;
}
}
Class weight implementation ActionListener {
public void action performed(action event e){
mass textfield . set editable(true);
}
}
Class textfield implements ActionListener {
public void action performed(action event e){
}
}
Class VerifyInputKeyAdapter implements KeyListener {
Keyevent e typed by public void (
}
Common void key (key event e) (
if (e.getKeyCode()! = KeyEvent。 VK_BACK_SPACE) {
char input char = e . getkey char();
string input = character . tostring(input char);
If (! input . matches(" \ \ d "){
e . consume();
} Otherwise {
string mass string = mass textfield . gettext();
int mass int = integer . parse int(mass string+input);
Double cost = massInt * costDouble
cost textfield . settext("+costs);
}
}
}
public void key released(key event e){
if (e.getKeyCode() == KeyEvent。 VK_BACK_SPACE) {
string mass string = mass textfield . gettext();
int mass int = integer . parse int(mass string . equals(" "? "0"
:mass tring);
Double cost = massInt * costDouble
cost textfield . settext("+costs);
}
}
}
}
Class print implements ActionListener {
public void action performed(action event e){
}
}
Class close implements ActionListener {
public void action performed(action event e){
system . exit( 1);
}
}
Class blank implements ActionListener {
public void action performed(action event e){
}
}
Category price {
Hash table ht;
Public price () {
ht = new Hashtable();
Ht.put ("Apple", new Double(6.00)););
Ht.put ("Pear", New Double (5.00));
Ht.put ("orange", new pair (7.00));
Ht.put ("banana", new Double(3.00)););
Ht.put ("lemon", new double (10.00));
Ht.put ("Peach", new Double(4.00)););
Ht.put ("strawberry", new Double(4.00)););
ht.put("Cherry ",new Double( 12.50));
Ht.put ("avocado", new double (15.00));
}
}
Basically meet your requirements ...
Let me give some advice to your code:
1, your variable name should conform to the java specification. For example, Apple button knows it's AppleButton at first sight, and your original BT2BT3 looks very tired.
2. The class name should start with a capital letter.
You ask me if you don't understand.
- Previous article:When did the WeChat ringtone come out?
- Next article:How to set up automatic reply SMS for incoming calls on Apple mobile phone?
- Related articles
- What is the discount rate of talent green card in Putuo District, Zhoushan City, Zhejiang Province?
- Changzhou Maternity Insurance Benefit Reimbursement Process for Male Employees
- Black lines often flash across the screen of iPhone7plus.
- The API server interface of mobile phone returned an exception.
- Bank of tianjin, how long does it take to transfer a large sum of money to the account?
- What does it mean for a man not to answer the phone or return to WeChat?
- I asked the leader to transfer the post, and the leader agreed, but it has been almost a year. Of course, there has been no post adjustment this year, and no text messages have been sent to the leader
- Gitzo sent a text message suspected of loan fraud. What does 202 1 mean?
- Where is the tt voice gobang?
- 20 14 Hunan Central South University Xiangya Hospital Recruitment Announcement