




全文预览已结束
下载本文档
版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
AWrongException.javapackage fangcheng;public class AWrongException extends Exception public AWrongException(String s) super(s);Rootx1x2.javapackage fangcheng;import java.awt.BorderLayout;import java.awt.Color;import java.awt.Font;import java.awt.event.ActionEvent;import java.awt.event.ActionListener;import javax.swing.JButton;import javax.swing.JFrame;import javax.swing.JLabel;import javax.swing.JPanel;import javax.swing.JScrollPane;import javax.swing.JTextArea;import javax.swing.JTextField;public class Rootx1x2 extends JFrame implements RootInterface,ActionListener /实现RootInterfacedouble a,b,c, b24ac, x1,x2;String y1,y2;JTextField textA,textB,textC; /数据对象的视图JTextArea roottext;JTextArea showArea; /数据对象的视图JButton button1,button2,button3; /控制器对象 Root root;public Rootx1x2(String astr,String bstr,String cstr) throws AWrongException, ExceptionsetTitle(求一元二次方程根);setBounds(300,300,150,300);init();setResizable(false);setVisible(true);setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);void init() throws AWrongException, Exceptionroot =new Root(0, 0, 0);textA=new JTextField(5);textB=new JTextField(5);textC=new JTextField(5);textA.setText(0);textB.setText(0);textC.setText(0);showArea=new JTextArea();button1= new JButton(求根);button2= new JButton(清空);button3= new JButton(退出);JPanel jp= new JPanel();jp.add(new JLabel(求一元二次方程根);jp.add(new JLabel(请输入系数a);jp.add(textA);jp.add(new JLabel(请输入系数b);jp.add(textB);jp.add(new JLabel(请输入系数c);jp.add(textC);jp.add(new JLabel(计08-5班 X S L);jp.setFont(new Font(Serif,Font.PLAIN,25);jp.setForeground(Color.pink);roottext = new JTextArea(4,15);String a=null,b=null,c=null;a=textA.getText();b=textB.getText();c=textC.getText();jp.add(button1);jp.add(button2);jp.add(button3);jp.add(roottext);add(jp);button1.addActionListener(new ActionListener() public void actionPerformed(ActionEvent e) if(Double.valueOf(textA.getText()=0)roottext.setForeground(Color.red);roottext.setText(二次项系数不能为零!);else if(root.b24ac(Double.valueOf(textA.getText(),Double.valueOf(textB.getText(),Double.valueOf(textC.getText()root.root_x1x2(Double.valueOf(textA.getText(),Double.valueOf(textB.getText(),Double.valueOf(textC.getText();roottext.setForeground(new Color(0,50,0);roottext.setText(一元二次方程根为:+root.getx1()+ , +root.getx2();elseroot.root_x1x2(Double.valueOf(textA.getText(),Double.valueOf(textB.getText(),Double.valueOf(textC.getText();roottext.setForeground(new Color(255,0,0);roottext.setForeground(Color.black);roottext.setText(一元二次方程根为:+root.gety1()+root.gety2()+i););button2.addActionListener(new ActionListener()public void actionPerformed(ActionEvent e)textA.setText(0);textB.setText(0);textC.setText(0);roottext.setText(null); roottext.setForeground(Color.black);); button3.addActionListener(new ActionListener() public void actionPerformed(ActionEvent e) System.exit(0); ); button1.addActionListener(this); button2.addActionListener(this); button3.addActionListener(this); public static void main(String args) throws AWrongException, ExceptionRootx1x2 r =new Rootx1x2(1,1,1);public void inputABC(String astr, String bstr, String cstr) throws AWrongException, Exception / TODO 自动生成方法存根public boolean b24ac(double a, double b, double c) / TODO 自动生成方法存根return false;public void root_x1x2(double a, double b, double c) / TODO 自动生成方法存根public void actionPerformed(ActionEvent e) / TODO 自动生成方法存根RootInterface.javapackage fangcheng;public interface RootInterfacepublic void inputABC(String astr,String bstr,String cstr) throws AWrongException, Exception;public boolean b24ac(double a,double b,double c); /求b*b-4*a*cpublic void root_x1x2(double a,double b,double c); /求根Root.javapackage fangcheng;import java.text.DecimalFormat;public class Root implements RootInterface /实现RootInterfacedouble a,b,c, b24ac, x1,x2;String y1,y2;public Root(String astr, String bstr, String cstr) throws AWrongException, ExceptioninputABC(astr,bstr,cstr);root_x1x2(a,b,c);public double getx1()return x1;public double getx2()return x2;public String gety1()return y1;public String gety2()return y2;public void inputABC(String astr,String bstr,String cstr) throws AWrongException, Exceptiona=Double.valueOf(astr);b=Double.valueOf(bstr);c=Double.valueOf(cstr); public boolean b24ac(double a,double b,double c)b24ac=b*b-4*a*c;if(b24ac=0&a!=0)return true;elsereturn false;public void root_x1x2(double a,double b,double c)DecimalFormat df = new java.text.DecimalFormat(0.00);if( b24ac=0&a!=0)x1=Double.valueOf(df.format(-1*b+Math.sqrt(b*b-4*a*c)/(2*a); x2=Do
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 2021年人民警察节活动训练学习心得与体会五篇
- 2025年教师招聘之《幼儿教师招聘》题库必背100题含答案详解(精练)
- 教师招聘之《幼儿教师招聘》综合提升测试卷及答案详解(典优)
- 2025年教师招聘之《小学教师招聘》通关提分题库及完整答案详解【各地真题】
- 教师招聘之《幼儿教师招聘》考试彩蛋押题附答案详解【模拟题】
- 教师招聘之《幼儿教师招聘》自测题库及参考答案详解(模拟题)
- 2025年教师招聘之《小学教师招聘》通关提分题库附答案详解【培优】
- 实商务英语综合教程(第一册)-课件 Unit 9 Business Environment
- 2025年新能源商用车辆在电力运输中的应用场景分析报告001
- 教师招聘之《幼儿教师招聘》练习题(一)附参考答案详解【典型题】
- 品质异常处理流程培训
- 《陆上风电场工程概算定额》NBT 31010-2019
- CFG桩复合地基沉降及承载力自动计算
- 浅析加强物资采购质量的措施
- 青岛版二年级下册万以内数的加减法竖式计算300题及答案
- 2024年天津港集团有限公司招聘笔试参考题库附带答案详解
- 传统体育运动在小学课堂中的应用课件教案
- 类脑计算与神经网络
- 手术授权申请表
- 2023年度全国出版专业技术人员职业资格考试-基础知识(初级)试题
- 2023届高考语文备考之整句与散句变换(10道真题含答案)
评论
0/150
提交评论