📄 nihe.java
字号:
package nihe;
import nihe.*;
import java.io.*;
import java.awt.*;
import java.awt.event.*;
public class NiHe implements ActionListener
{
Frame f;
FileDialog fd;
Button btn1,btn2,btn3;
TextField tf1,tf2;
Label lb1,lb2,lb3,lb4;
Checkbox cb1,cb2;
CheckboxGroup cg;
public static void main(String args[])
{
new NiHe();
}
public NiHe()
{
f=new Frame("曲线拟合计算软件");
fd=new FileDialog(f);
btn1=new Button("打开");
btn2=new Button("保存");
tf1=new TextField(20);
tf2=new TextField(20);
lb1=new Label("请点击\"打开\"按钮打开数据文件:");
lb2=new Label("文件的打开路径为:");
lb3=new Label("请点击\"保存\"按钮保存结果文件:");
lb4=new Label("文件的保存路径为:");
tf1.setEditable(false);
tf2.setEditable(false);
Panel p1=new Panel(new GridLayout(4,2));
p1.add(lb1);
p1.add(btn1);
p1.add(lb2);
p1.add(tf1);
p1.add(lb3);
p1.add(btn2);
p1.add(lb4);
p1.add(tf2);
cg=new CheckboxGroup();
cb1=new Checkbox("直线拟合",true,cg);
cb2=new Checkbox("曲线拟合",false,cg);
Panel p2=new Panel();
p2.add(cb1);
p2.add(cb2);
btn3=new Button("计算");
btn1.addActionListener(this);
btn2.addActionListener(this);
btn3.addActionListener(this);
f.addWindowListener(new WindowEventHandler());
f.add(p1,BorderLayout.NORTH);
f.add(p2,BorderLayout.CENTER);
f.add(btn3,BorderLayout.SOUTH);
f.pack();
f.setVisible(true);
f.setResizable(false);
}
public void actionPerformed(ActionEvent e)
{
if(e.getSource()==btn1)
{
fd.setMode(FileDialog.LOAD);
fd.setTitle("打开");
fd.setVisible(true);
if(fd.getDirectory()==null || fd.getFile()==null)
tf1.setText(tf1.getText());
else
tf1.setText(fd.getDirectory()+fd.getFile());
if(fd.getDirectory()!=null)
new ShuRu(tf1.getText());
}
if(e.getSource()==btn2)
{
fd.setMode(FileDialog.SAVE);
fd.setTitle("保存");
fd.setVisible(true);
if(fd.getDirectory()==null || fd.getFile()==null)
{
tf2.setText(tf2.getText());
}
else
tf2.setText(fd.getDirectory()+fd.getFile());
}
if(e.getSource()==btn3)
{
if(cb1.getState())
new ZhiXianShuChu(tf2.getText());
else
new QuXianShuChu(tf2.getText());
}
}
}
class WindowEventHandler extends WindowAdapter
{
public void windowClosing(WindowEvent e)
{
System.exit(0);
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -