我希望在界面上用键盘输入2个数据,并且可以选择几个设定好的数据,然后点击计算(计算过程我来写),然后点击计算结果,结果可以显示在记事本上或者显示在当前界面上,希望得到源代码,在线等
解决方案 »
- java -d参数 和 policy文件的问题
- 插入图片不显示的问题
- 一个小技术细节问题。
- 关于String和StringBuffer的一个问题,看书时遇到的疑惑
- 系统时间问题
- 我的服务器是linux的我用了CharDirector包画图面 可是在linux下中文的文字死活无法显示请问 是什么问题???重谢
- 从不结贴的人:zouge139
- 包含javaapplet的网页中.class文件一般保存在什么地方呢
- 有james + javamail开发经验的朋友请进,关于邮箱容量限制的问题(100分)
- 100分:请各位前辈列举JAVA应用的典型案例.谢谢!
- 想打开一个网页,点了按钮之后却没一点反应?
- 请教各位高手帮我这个新人解决一个程序问题!
试一下调用这个类:
import java.io.*;public class Console
{
public static String readString()
{
String str = new String();
BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
try
{
str = in.readLine();
}
catch(IOException e)
{
System.out.println("Console.readString:Unknown error...");
System.exit(-1);
} return str;
} public static double readDouble()
{
try
{
return Double.valueOf(readString().trim()).doubleValue();
}
catch(NumberFormatException ne)
{
System.err.println("Consle.readDouble:Not a double...");
System.exit(-1);
return 0.0;
} } public static int readInt()
{
try
{
return Integer.valueOf(readString().trim()).intValue();
}
catch(NumberFormatException ne)
{
System.err.println("Consle.readDouble:Not a integer...");
System.exit(-1);
return -1;
}
}
}
import java.awt.event.*;
import javax.swing.*;public class User extends JFrame implements ActionListener{
private JButton ok0,ok1;
private JRadioButton rb0,rb1,rb2;
private ButtonGroup group;
private JTextField num0,num1,decimalNum;
private JLabel label0,label1,label3,result;
public User(String title){
super(title);
this.setLayout(null);
this.setDefaultCloseOperation(EXIT_ON_CLOSE);
ok0=new JButton("预设值计算");
ok0.setSize(80,30);
ok0.setLocation(20,200);
add(ok0);
ok0.addActionListener(this);
ok1=new JButton("计算");
ok1.setSize(80,30);
ok1.setLocation(180,200);
add(ok1);
ok1.addActionListener(this);
rb0=new JRadioButton("0.177 1.54");
rb0.setSize(100,30);
rb0.setLocation(20,50);
add(rb0);
rb1=new JRadioButton("0.381 1.54");
rb1.setSize(100,30);
rb1.setLocation(20,100);
add(rb1);
rb2=new JRadioButton("0.4 1.8");
rb2.setSize(100,30);
rb2.setLocation(20,150);
add(rb2);
group=new ButtonGroup();
group.add(rb0);
group.add(rb1);
group.add(rb2);
label0=new JLabel("开始高度");
label0.setSize(100,30);
label0.setLocation(150,50);
add(label0);
num0=new JTextField();
num0.setSize(80,30);
num0.setLocation(210,50);
add(num0);
label1=new JLabel("最后高度");
label1.setSize(100,30);
label1.setLocation(330,50);
add(label1);
num1=new JTextField();
num1.setSize(80,30);
num1.setLocation(390,50);
add(num1);
label3=new JLabel("小数位数");
label3.setSize(100,30);
label3.setLocation(150,100);
add(label3);
decimalNum=new JTextField();
decimalNum.setSize(80,30);
decimalNum.setLocation(210,100);
add(decimalNum);
result=new JLabel("结算结果显示在这里");
result.setSize(200,30);
result.setLocation(300,200);
add(result);
setSize(500,300);
setLocation(200,100);
setVisible(true);
}
public void actionPerformed(ActionEvent ae){
if(ae.getSource()==ok0){
//计算预设值
}
if(ae.getSource()==ok1){
//计算自定义值,使用getText()获取输入内容,并转成你需要的参数类型
//一些相关判断还是不可少的,比如输入输入是否为空,是否为数值
}
}
public static void main(String[] args){
User user=new User("流量计算");
}
}
import javax.swing.*;
class A
{
public static void traffic(double c,double n,double beginHigh,double endHigh,int fraction)
{
System.out.println();
System.out.println(" C= "+c+", N= "+n);
System.out.println();
NumberFormat formatter = NumberFormat.getNumberInstance(); //import java.text.*
formatter.setMinimumFractionDigits(fraction); //小数点最少位,没有的显示0 for (double high=beginHigh;high<=endHigh ;high++ )
{
double stream=1000*c*Math.pow(high/100,n); // 除100将单位换算为米 乘1000表示单位为升/秒
String s=formatter.format(stream);
if (high<10)
{
System.out.print(" ");
}else if (high<100)
{
System.out.print(" ");
}
System.out.println(high+"厘米 流量 "+s);
}
System.out.println();
}
}class B
{
public static void main(String[] args)
{
String name= JOptionPane.showInputDialog
("0.177 1.54选1 0.381 1.54选2 0.4 1.8选3 ");
int choose =Integer.parseInt(name);
String input1 = JOptionPane.showInputDialog
("开始高度");
double beginHigh =Double.parseDouble(input1); String input2 = JOptionPane.showInputDialog
("最后高度");
double endHigh =Double.parseDouble(input2); String name2 = JOptionPane.showInputDialog
(" 显示小数位数,最多取17位数小数");
int fraction =Integer.parseInt(name2); A a=new A(); switch (choose)
{
case 1:
A.traffic(0.177,1.54,beginHigh,endHigh,fraction);
break;
case 2:
a.traffic(0.381,1.54,beginHigh,endHigh,fraction);
break;
case 3:
a.traffic(0.4,1.8,beginHigh,endHigh,fraction);
break;
default:
System.out.println("输入错误");
}
System.exit(0);
}
}
javac User.java
User.java:103:'class'or'interface'expected
s
^
1 error 不知道什么意思?请帮我看看?