急需一些java小程序代码
2019-03-12 17:01:43
微信公开课小程序热门讨论「急需一些java小程序代码」最新回复-importjava.awt.*;importjava.awt.event.*;importjavax.swing.*;publicclassCalculatorextendsJFrame{privateContainercontainer;privateGridBagLayoutlayout;privateGridBagConstraintsconstraints;privateJTextFielddisplayField;privateStringlastCommand;privatedoubleresult;privatebooleanstart;publicCalculator(){super(Calculator);container=getContentPane();layout=newGridBagLayout();container.setLayout(layout);constraints=newGridBagConstraints();start=true;result=0;lastCommand==;displayField=newJTextField(20);displayField.setHorizontalAlignment(JTextField.RIGHT);constraints.gridx=0;constraints.gridy=0;constraints.gridwidth=4;constraints.gridheight=1;constraints.fill=GridBagConstraints.BOTH;constraints.weightx=100;constraints.weighty=100;layout.setConstraints(displayField,constraints);container.add(displayField);ActionListenerinsert=newInsertAction();ActionListenercommand=newCommandAction();addButton(Backspace,0,1,2,1,insert);addButton(CE,2,1,1,1,insert);addButton(C,3,1,1,1,insert);addButton(7,0,2,1,1,insert);addButton(8,1,2,1,1,insert);addButton(9,2,2,1,1,insert);addButton(/,3,2,1,1,command);addButton(4,0,3,1,1,insert);addButton(5,1,3,1,1,insert);addButton(6,2,3,1,1,insert);addButton(*,3,3,1,1,command);addButton(1,0,4,1,1,insert);addButton(2,1,4,1,1,insert);addButton(3,2,4,1,1,insert);addButton(,3,4,1,1,command);addButton(0,0,5,1,1,insert);addButton(+/,1,5,1,1,insert);addButton(.,2,5,1,1,insert);addButton(+,3,5,1,1,command);addButton(=,0,6,4,1,command);setSize(300,300);setVisible(true);}privatevoidaddButton(Stringlabel,introw,intcolumn,intwith,intheight,ActionListenerlistener){JButtonbutton=newJButton(label);constraints.gridx=row;constraints.gridy=column;constraints.gridwidth=with;constraints.gridheight=height;constraints.fill=GridBagConstraints.BOTH;button.addActionListener(listener);layout.setConstraints(button,constraints);container.add(button);}privateclassInsertActionimplementsActionListener{publicvoidactionPerformed(ActionEventevent){Stringinput=event.getActionCommand();if(start){displayField.setText();start=false;if(input.equals(+/))displayField.setText(displayField.getText()+);}if(!input.equals(+/)){if(input.equals(Backspace)){Stringstr=displayField.getText();if(str.length()0)displayField.setText(str.substring(0,str.length()1));}elseif(input.equals(CE)||input.equals(C)){displayField.setText(0);start=true;}elsedisplayField.setText(displayField.getText()+input);}}}privateclassCommandActionimplementsActionListener{publicvoidactionPerformed(ActionEventevt){Stringcommand=evt.getActionCommand();if(start){lastCommand=command;}else{calculate(Double.parseDouble(displayField.getText()));lastCommand=command;start=true;}}}publicvoidcalculate(doublex){if(lastCommand.equals(+))result+=x;elseif(lastCommand.equals())result=x;elseif(lastCommand.equals(*))result*=x;elseif(lastCommand.equals(/))result/=x;elseif(lastCommand.equals(=))result=x;displayField.setText(+result);}publicstaticvoidmain(String[]args){Calculatorcalculator=newCalculator();calculator.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);}}
21点游戏代码:importjava.awt.Color;importjava.awt.Font;importjava.awt.event.ActionEvent;importjava.awt.event.ActionListener;importjavax.swing.JButton;importjavax.swing.JFrame;importjavax.swing.JLabel;importjavax.swing.JOptionPane;importjavax.swing.SwingConstants;importjavax.swing.border.LineBorder;publicclassgame21extendsJFrame{privateJLabellabel_2;privateintnumber;privateintsum;finalJLabellabel=newJLabel();finalJLabellabel_1=newJLabel();publicstaticvoidmain(String[]args){newgame21();}publicgame21(){super(21点?!);getContentPane().setLayout(null);this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);finalJButtonbutton=newJButton();button.addActionListener(newActionListener(){publicvoidactionPerformed(finalActionEventarg0){onClick();}});button.setText(出牌);button.setBounds(170,350,106,28);getContentPane().add(button);label.setBorder(newLineBorder(Color.black,1,false));label.setHorizontalAlignment(SwingConstants.CENTER);label.setFont(newFont(,Font.BOLD,26));label.setText(背面);label.setBounds(158,81,137,153);getContentPane().add(label);label_1.setText(你已经拥有的牌:);label_1.setBounds(109,22,270,45);getContentPane().add(label_1);this.setBounds(200,300,501,528);this.setVisible(true);getContentPane().add(getLabel_2());}publicintrandNumber(){try{Thread.sleep(10);}catch(InterruptedExceptione){e.printStackTrace();}return(int)(Math.random()*10+1);}publicvoidonClick(){number=this.randNumber();this.sum+=number;label.setText(+number);StringstrTemp=this.label_1.getText();strTemp+=+number+;label_1.setText(strTemp);Stringtemp=合计:+sum;label_2.setText(temp);isWin();}publicvoidisWin(){if(sum21){JOptionPane.showMessageDialog(this,你输了);clear();return;}elseif(sum==21){JOptionPane.showMessageDialog(this,你赢了);clear();return;}else{inti=JOptionPane.showOptionDialog(this,是否继续?,提示,JOptionPane.OK_CANCEL_OPTION,JOptionPane.INFORMATION_MESSAGE,null,null,null);if(i==JOptionPane.OK_OPTION){onClick();}elsereturn;}}privatevoidclear(){label_2.setText(合计:);sum=0;number=0;label_1.setText(你已经拥有的牌:);}/***@return*/protectedJLabelgetLabel_2(){if(label_2==null){label_2=newJLabel();label_2.setText(合计:);label_2.setBounds(313,35,66,18);}returnlabel_2;}}都是编译成功的java源代码,希望对你有帮助! 更多有关「急需一些java小程序代码」的疑问请扫码关注微信公开课+小程序!
21点游戏代码:importjava.awt.Color;importjava.awt.Font;importjava.awt.event.ActionEvent;importjava.awt.event.ActionListener;importjavax.swing.JButton;importjavax.swing.JFrame;importjavax.swing.JLabel;importjavax.swing.JOptionPane;importjavax.swing.SwingConstants;importjavax.swing.border.LineBorder;publicclassgame21extendsJFrame{privateJLabellabel_2;privateintnumber;privateintsum;finalJLabellabel=newJLabel();finalJLabellabel_1=newJLabel();publicstaticvoidmain(String[]args){newgame21();}publicgame21(){super(21点?!);getContentPane().setLayout(null);this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);finalJButtonbutton=newJButton();button.addActionListener(newActionListener(){publicvoidactionPerformed(finalActionEventarg0){onClick();}});button.setText(出牌);button.setBounds(170,350,106,28);getContentPane().add(button);label.setBorder(newLineBorder(Color.black,1,false));label.setHorizontalAlignment(SwingConstants.CENTER);label.setFont(newFont(,Font.BOLD,26));label.setText(背面);label.setBounds(158,81,137,153);getContentPane().add(label);label_1.setText(你已经拥有的牌:);label_1.setBounds(109,22,270,45);getContentPane().add(label_1);this.setBounds(200,300,501,528);this.setVisible(true);getContentPane().add(getLabel_2());}publicintrandNumber(){try{Thread.sleep(10);}catch(InterruptedExceptione){e.printStackTrace();}return(int)(Math.random()*10+1);}publicvoidonClick(){number=this.randNumber();this.sum+=number;label.setText(+number);StringstrTemp=this.label_1.getText();strTemp+=+number+;label_1.setText(strTemp);Stringtemp=合计:+sum;label_2.setText(temp);isWin();}publicvoidisWin(){if(sum21){JOptionPane.showMessageDialog(this,你输了);clear();return;}elseif(sum==21){JOptionPane.showMessageDialog(this,你赢了);clear();return;}else{inti=JOptionPane.showOptionDialog(this,是否继续?,提示,JOptionPane.OK_CANCEL_OPTION,JOptionPane.INFORMATION_MESSAGE,null,null,null);if(i==JOptionPane.OK_OPTION){onClick();}elsereturn;}}privatevoidclear(){label_2.setText(合计:);sum=0;number=0;label_1.setText(你已经拥有的牌:);}/***@return*/protectedJLabelgetLabel_2(){if(label_2==null){label_2=newJLabel();label_2.setText(合计:);label_2.setBounds(313,35,66,18);}returnlabel_2;}}都是编译成功的java源代码,希望对你有帮助! 更多有关「急需一些java小程序代码」的疑问请扫码关注微信公开课+小程序!
标签:微信公开课,小程序
「急需一些java小程序代码」热议话题订阅
方法1:微信扫描微信公开课小程序码即可订阅热议话题「急需一些java小程序代码」
方法2:微信搜索微信公开课小程序名称进入,即可订阅热议话题「急需一些java小程序代码」
方法3:微信网页访问即速商店,长按识别微信公开课小程序码即可订阅热议话题「急需一些java小程序代码」
微信公开课小程序热议话题「急需一些java小程序代码」由微信公开课原创摘录于微信小程序商店shop.jisuapp.cn,转载请注明出处。
微信公开课热议话题「急需一些java小程序代码」由微信公开课开发者向微信用户提供,并对本服务内容、数据资料及其运营行为等真实性、合法性及有效性承担全部责任。
微信公开课小程序
更新时间:2019-03-12 17:01:43
>
__methodCallerx27;ofundefined
>-404011cloudfunctionexecutionerror
>,请补充选择商家自营-预付卡销售-发行方类目,并在基础信息处申请该类目,通过
>:host在模拟器中显示无效
>:请在小程序服务页面上架正式(非测试)内容或商品后重新提交审核
>.net 微信小程序 上传图片
>'setTimeout'的问题
>‘三朵里熙SPA主题减压空间’为什么搜索关键词‘三朵里‘搜不到
>‘扫普通链接二维码打开小程序‘中设置为体验版,扫码打开是线上版本
>“cloudfunctions**indexjs”gitignore
>“NO ULINK DEVICE FOUND”是怎么回事
>“万马掌上校园”的类目审核
>“上线了”公司开发的微信小程序怎么样?
>“产品是否一定需要条形码”
>