求简单的JAVA小程序的源代码,“Java就业培训教程”P34源程序列表:rigen.javaclass推广{公共静态void main(String args []){byte b = 50; char c ='a';短s = 1024; int i = 50000; float f = 5.67f;双D = .1234;双重结果=(f * b)+(I / c) - (d * s); system.out.println((f * b)+“+”+(I / C)+“ - ”+(d * s)); system.out.println(“结果=”+结果);“Java就业培训教程”P35源程序列表:testscope.javapublic类testscope {public static void main(String [] args){int x = 12; {int q = 96; // x和q可以在system.out.println(“x为”+ x)中使用; system.out.println(“q是”+ q); ... isum =添加(3; *错误行;> / i ++){system,10); System.javapublic类TestDo {公共静态void main(String [] args){int x = 3; / sy.干; + x [i]); fsum = add(3.println(); / system;}}}“Java就业培训课程”P67Source代码列表;&gt,4));第一个面积是“}系统:func2.out;}}”java就业培训教程“p39源计划列表;)。Println(”+ getarea(2; y = y&gt.println).print(Ib [J ]); / X! = 0 && y == y /,3); 3;第一个焦点是“,0; j ++){system;系统:testvar;}}“Java就业培训教程”P47源代码公共课程测试; {公共静态void main(String [] args){int x = 0,s范围* / 1超出q;)。出,int y){返回x * y; Q Q od .out,5).out;}}“Java就业培训教程”P35源计划列表。 OrryCopy(IA; OK1“X)系统;第二型焦轴是”公共静态INT GETAREA(INT X,10)系统,6; + INTEGER.Println(“; F.或(int i = 0);而(x == 0){system;系统; *“for(int i = 0out:testdo; wrap} system; x = new int [100] .print(&quot.out;); system.out.println(”Ia; x“)。println(& “testArray; /.out; +结果);}公共静态void主(Strin)g [] args){drawrectangle(3,5.out,0;系统,只有x可用; i / .javapublic类testarraycopy {公共静态void main(String [] args){int = new int = new int = 1;} return x * y; system.println(“+” - “/.print(&&键,int y.out.println (); IB.2; IY ++; 10.printlln(),2;系统。out; 4.out:printdnum; y; = 0){return-1; /。println(“getarea(6;系统。 print(“} q = x.println(”system.length;} public static int add)int x; /:func3;}公共静态void main(String [] args){int区域= getarea(3.out;下面;下面打印第二个矩形program代码(int i = 0.print(ia [i]); system.out; + y).javapublic类func1 {public静态void main(string [] args){/10.println(“)。出。出局; 0x800000> /.javapublic类func2 {公共静态void drawrectangle(int xprintln(“= 0 || yx = x + 1:test,6.javapublic类testvar {public static void main(String [] args){ int x,5).out.67f.println(); char c ='/下面打印了第三个矩形程序代码(int i = 0; {int q = 96,从下标0的位置开始存储: testarraycopy; a'.javapublic类测试{公共静态void main(String [] args){int isum.out; y =&out.out.5); c) - (d * s);此x未初始化;系统; JSecond面积是“x是”i ++){for(int j = 0out,4 .println(),5),3; +地区).1234,5).out;我<+ getarea(2;}}“Java E就业培训教程“P64源计划列表;结果=”}}}“Java就业培训教程”P73源代码列表; + i +“
求一个简单的Java 小程序源文件!高分悬赏!,给你一个计算器,导入java.awt.borderlayout;导入java.awt.gridlayout;导入java.awt.Event.mouseEvent;导入java.awt.Event.mouseListener;导入java.text.decimalformat;导入javax.swing .jbutton;导入javax.swing.jframe;导入javax.swing.jpanel;导入javax.swing.jtextfield;公共类计算器{//计算器面板私有JFRAME F =新JFRAME(“计算器”); //输入表面私有jpanel inputpanel = new jpanel(); // double jpanel(); //调整面板私有jpanel operationpanel = new jpanel(); //数字面板私有jpanel buttonspanel = new jpanel(); //输入数据文本框私有jtextfield输入= new jtextfield(20); // q.退私有jbutton backspace = new jbutton(“backspace”); //空私人jbutton ce =新jbutton(“ce”); //删除rivat.e jbutton c =新jbutton(“c”); //四个算术符号键私有jbutton添加=新jbutton(“+”);私人jbutton sub =新jbutton(“ - ”);私人jbutton mul =新jbutton(“*”);私人JButton div =新jbutton(“/”); //十进制点私有jbutton decimal =新jbutton(“。”); //等私有jbutton等于=新jbutton(“=”); //编号密钥私有jbutton zero = new jbutton(“0”);私人jbutton一个=新jbutton(“1”);私人jbutton两=新jbutton(“2”);私人jbutton三=新jbutton(“3”);私人jbutton四=新jbutton(“4”);私人jbutton文件=新jbutton(“5”);私人Jbutton六=新jbutton(“6”);私人JButton七=新jbutton(“7”);私人jbutton电=新jbutton(“8”);私人jbutton nine =新jbutton(“9”); privATE字符串NUM1 =“”; //保存第一个算术数字私有字符串运算符=“”//保存操作符号公共静态void main(String [] args){new compulator(); //新计算器实例}公共计算器(){//添加组件,布局InputPanel.add(输入); f.add(InputPanel,BorderLayout.north)MovertingPanel.Add(Backspace); operationPanel.add(CE); operationPanel.add(c); F.ADD(operationPanel,BorderLayout.Center); buttonspanel.add(sub); Buttonl.add(MUL); buttonspanel.add(div); buttonspanel.add(二); buttonspanel.add(三); buttonspanel.add(零); buttonspanel.add(四); buttonspanel.add(五); buttonspanel.add(六); buttonspanel.add(十进制); buttonspanel.add(八); buttonspanel.add(九); buttonspanel.add(相等); buttonspanel.setLayout GridLayout(4,4)); F.ADD(Buttonspanel,Borderlayout.South); //注册了每个组件侦听事件Backspace.addMouseListener(新的OperationMouseListener(新的OperationMousEristener()); C.AddMouseristener(新的操作MouseRistener()); DECIMAL.ADDMOUSELISTENER(NEW OperationMouseListener());相等.AddMouseListener(新的omingMouseListener()); //注册四个操作Monitor Add.addMouseListener(新CalcmouseListener()); Sub.addMouseListener(新CalcmouseListener()); Mul.addMouseListener(新CalcmouseListener()); Div.AdmouseListener(新CalcmouseListener()); //注册事件侦听器号零.AddmouseListener(新的数字轿enterener()); one.addmouseListener(new numbermouseListener());二.AddmouseListener(new numbermouselistener());三个.AddmouseListener(新nUmbermouseListener());四.AddmouseListener(新的数字轿坐标器()); Five.addMouseListener(新的数字轿坐标器());六.AddmouseListener(新的NumberMouseListener());七.AddmouseListener(新的数字轿坐标者());八.AddMouseListener(New NumberMouseListener())nine.addmouseListener(新号码); F.SetVisible(真实); F.Pack(); f.setDefaultCloseoperation(JFrame.exit_On_Close);私人类NumberMouseListener实现MouseListener {public void mouseclicked(input.gettext()。修剪()。等于(“0”)){//如果文本框已经是0,结果或0input.settext((jbutton)e.getsource())。 gettext()。剪裁());} else {//否则,将0添加到后面,例如文本框为1,结果是10. Setext(Input.getText()。concat((jbutton)e.getsource())。GetText()。 Trim()));}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}} public void mouseEntered(mousevent e){} public void mousexitted(mousevent e){}公共空白鼠标抑制(mousevent e){} public void mousereled(mousevent e){}}私人类CalcmouseListener实现MouseListener {//如果输入是操作符号,并且结果存储了第一操作标志公共void mouseclicked(mousevent e){num1 = input.gettext()。修剪(); Input.settext(“”);操作员=((jbutton)e.getsource())。 gettext()。剪裁();}公共空白mouseEntered(mousevent e){} public void mousexited(mousevent e){} public void mouse(mousevent e){} public void mouseReleased(mousevent e){}}私人类操作restenering mouseListener {public void Mouseclicked(mousevent e){if(e.getsource()== backspace){//转义密钥,删除一个,直到没有字符删除字符串infuttext = input.gettext(); if(inputtext.length()> 0){input.settext(inputtext.substring(0,inputtext.length() - 1));}否则if(e.getsource()== c){input.settext( “0”); // c,清空所有算术数和符号num1 =“”;} else if(e.getsource()== ce){input.settext(“0”); // ce - >将文本框架放到0} elly if(e.getsource()== decimal){string text = input.gettext().trim(); //如果按下小数点,如果文本框已经有小数点,则不执行任何操作,否则添加小数点(text.indexof(“)== -1){input.settext(text.concat (“。”);}}否则if(e.getsource()==等于){//如果它是一个相等的数字,如果(!“){if(”)。!Infut.gettext()。Trim() 。等于(“)){双倍结果= 0d; if(运算符.Equals(“+”)){//执行加法操作结果= double.parsedouble(num1)+ double.parsedouble(input.gettext()。剪裁());}否则如果(运算符。 - “)){//减法计算结果= double.parsedouble(num1) - double.parsedouble(input.gettext()。trim());} else}(”*“)){//乘法结果= double。 parsedouble(num1)* double.parsedouble(input.gettext()。修剪());} else f(运算符.Equals(“/”)){// divion操作结果= double.parsedouble(num1)/ double.parsedouble (input.gettext()。Trim());} //格式化最终结果,请保留两个十进制input.settext(新DecimalFormat)。格式(结果));}}}}}}}} public void mouseEntered(mousevent e){} public void mousexitted(mousevent e){} public void mouse lement(mousevent e){} publetIC void mouseeleased(mousevent e){}}}}}}}}}}}}}}}}}}}}}}}}
求一个200行以上的Java小程序代码,有一个匿名的用户代码,非常好,非常强大的导入java.awt.bordlayout;导入java.awt.Color;导入java.awt.gridlayout;导入java.awt.Event.ActionEvent;导入java.awt.Event.ActionListener;导入javax.swing.jbutton;导入javax.swing.jframe;导入javax.swing.jpanel;导入javax.swing.jtextfield;类计算器扩展JFrame实现ActionListener {Private Final String []键= {“7”,“8”,“9”,“9”,“9”,“/”,“SQRT”,“4”,“5”,“5”,“6”,“*” ,“%”,“1”,“2”,“3”,“ - ”,“1 / x”,“0”,“+/-”,“。”,“+”,“=”};私有最终字符串[]命令= {“backspace”,“ce”,“c”};私人最终字符串[] m = {“”,“mc”,“mr”,“ms”,“ms”,“m +”};私有jbutton键[] =新jbutton [keys.length];私有jbutton命令[] = new jbutton [command.length];私人JButton M [] =新j按钮[M.Length]; Private JTextField结果将= New JTextField(“0”);私有布尔先装= TRUE;私人双重结果= 0.0;私有字符串运算符=“=”;私有布尔操作validflag = true;公共计算器(){super();在里面 (); this.setbackground(color.light_gray; this.settitle(“计算器”); this.setlocation(500,300); this.setresizable(false); this.pack();} private void init(){resulttext.sethorizonalalignment() JTextField。右图);结果文本.SEDITATE(FALSE);结果文本.SetBackground(Color.White); JPanel CalckeysPanel = New JPanel(); CalckeysPanel.SetLayout(New GridLayout); for(int i = 0 i < KEYS.length; i++) { keys[i] = new JButton(KEYS[i]); calckeysPanel.add(keys[i]); keys[i].setForeground(Color.blue); } keys[3].setForeground(Color.red); keys[8].setForeground(Color.red); keys[13].setForeground(Color.red); keys[18].setForeground(Color.red); keys[19].setForeground(Color.red); JPanel commandsPanel = new JPanel(); commandsPanel.setLayout(new GridLayout(1, 3, 3, 3)); for (int i = 0; i < COMMAND.length; i++) { commands[i] = new JButton(COMMAND[i]); commandsPanel.add(commands[i]); commands[i].setForeground(Color.red); } JPanel calmsPanel = new JPanel(); calmsPanel.setLayout(new GridLayout(5, 1, 3, 3)); for (int i = 0; i < M.length; i++) { m[i] = new JButton(M[i]); calmsPanel.add(m[i]); m[i].setForeground(Color.red); } JPanel panel1 = new JPanel(); panel1.setLayout(new BorderLayout(3, 3)); panel1.add("North", commandsPanel); panel1.add("Center", calckeysPanel); JPanel top = new JPanel(); top.setLayout(new BorderLayout()); top.add("Center", resultText); getContentPane().setLayout(new BorderLayout(3, 5)); getContentPane().add("North", top); getContentPane().add("Center", panel1); getContentPane().add("West", calmsPanel); for (int i = 0; i < KEYS.length; i++) { keys[i].addActionListener(this); } for (int i = 0; i < COMMAND.length; i++) { commands[i].addActionListener(this); } for (int i = 0; i < M.length; i++) { m[i].addActionListener(this); } } public void actionPerformed(ActionEvent e) { String label = e.getActionCommand(); if (label.equals(COMMAND[0])){ handleBackspace(); } else if (label.equals(COMMAND[1])) { resultText.setText("0"); } else if (label.equals(COMMAND[2])){ handleC(); } else if ("0123456789.".indexOf(label) > = 0) {handlenuber(标签);} else {showeroperator(标签);}}}}}}私有voidexpentbackspace(){string text = resulttext.gettext(); int i = text.length();如果(i> 0){text = text.substring(0,i - 1); if(text.length()== 0){RESHETTEXT.SETTEXT(“0”); firstdigit = true;运算符= “=”;}其他{resultText.setText(文本);}}}私人无效handleNumber(String键){如果(firstDigit){resultText.setText(KEY);否则if((“(”(“(”(),结果文本.gettext()。indexof(“。”)<0)){eSuceStxt.settext(RequestText.gettext()+“。”。“);否则如果(!”) {suceStxt.settext(RESHERTTEXT.GETTEXT()+键);} firstdigit = false;私有void handlec(){exculttext.settext(“0”)fidstdigit = true; operator =“=”;}私有void skoweoperator(字符串键){if(运算符。(“/”)){if(getnumberfromtext()== 0.0){operatevalinalflag = false;结果文本.settext“smbd”);} else {scessnum / = getnumberfromtext();}否则如果(运算符.Equals){if(seruestnum == 0.0){operatevalidflag = false; resulttext.settext(“归零无反转号”);} else {seaseNum = 1 / seuteNum;}否则如果(运算符。 ){scessnum - = getNumberfromText();否则f(“*”)){seaseNum * = getNumberfromText();}否则如果(“sqrt”)){结果=数学。sqrt(shiftnum);}否则如果(运算符) .equals)){scestnum = seruteNum / 100;}否则如果(运算符。(运算符)){seuteN = seuteNAUM *(-1)}否则if(“=”)){shuestnum = getnumberfromtext() ;}如果(operatevalidflag){long t1; double t2; t1 =(long)结果; t2 = seruteNum - t1;如果(t2 = = 0){resulttext.settext(string.valueof(t1)); else {resulttext .settext(string.valueof(sequestnum));}}}}}}}}}}}}}运算符=键; firstdigit = true;操作validflag = true;私人双层getnumberfromtext(){double结果= 0;尝试{结果= double.valueof(结果文本和提示())doublevalue();} catch(numberformatexception e){}返回结果;}公共静态void main(string args []){calculator calculator1 =新计算器; Calculator1.Setvisible(真实); Calculator1.setDefaultCloseoperation(JFrame.exit_On_Close);}}}
责任编辑(
白石隼也)
以上就是关于**java小程序源码,答题小程序源码前后端源码**的全部内容,了解更多请关注蚂蚁资源网。