📄 frame_show.java
字号:
软件学院 王玉馥(1291403166)03级4班
package dataSmall ;
import java.io.*;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
/*创建程序窗体文件
*/
public class Frame_show extends JFrame {
JPanel contentPane;
JMenuBar jMenuBar1 = new JMenuBar();
JMenu jMenuFile = new JMenu();
JMenuItem jMenuFileExit = new JMenuItem();
BorderLayout borderLayout1 = new BorderLayout();
JMenuItem jMenuItem1 = new JMenuItem();
JMenuItem jMenuItem2 = new JMenuItem();
JMenu jMenu1 = new JMenu();
JMenuItem jMenuItem3 = new JMenuItem();
JTextArea jTextArea1 = new JTextArea();
JFileChooser jFileChooser1 = new JFileChooser();
MyWindow result = new MyWindow("Show result");
JToolBar jToolBar = new JToolBar();
JLabel jLabel1 = new JLabel();
JTextArea jTextArea2 = new JTextArea();
JLabel jLabel2 = new JLabel();
JTextArea jTextArea3 = new JTextArea();
JLabel jLabel3 = new JLabel();
JTextArea jTextArea4 = new JTextArea();
//Construct the frame
public Frame_show() {
enableEvents(AWTEvent.WINDOW_EVENT_MASK);
try {
jbInit();
}
catch(Exception e) {
e.printStackTrace();
}
}
//Component initialization
private void jbInit() throws Exception {
contentPane = (JPanel) this.getContentPane();
contentPane.setLayout(borderLayout1);
this.setSize(new Dimension(465, 362));
this.setTitle("数据挖掘");
jMenuFile.setText("File");
jMenuFileExit.setText("Exit");
jMenuFileExit.addActionListener(new Frame_show_jMenuFileExit_ActionAdapter(this));
jMenuItem1.setText("open");
jMenuItem1.addActionListener(new Frame_show_jMenuItem1_actionAdapter(this));
jMenuItem2.setText("close");
jMenuItem2.addActionListener(new Frame_show_jMenuItem2_actionAdapter(this));
jMenu1.setText("FindMax");
jMenuItem3.setText("Find");
jMenuItem3.addActionListener(new Frame_show_jMenuItem3_actionAdapter(this));
jTextArea1.setText("");
jLabel1.setText(" From ");
jTextArea2.setText("0.3");
jLabel2.setText(" To ");
jTextArea3.setText("0.8");
jLabel3.setToolTipText("");
jLabel3.setText(" Step ");
jTextArea4.setText("0.1");
jTextArea4.setTabSize(8);
jMenuFile.add(jMenuItem1);
jMenuFile.add(jMenuItem2);
jMenuFile.add(jMenuFileExit);
jMenuBar1.add(jMenuFile);
jMenuBar1.add(jMenu1);
jMenu1.add(jMenuItem3);
contentPane.add(jTextArea1, BorderLayout.CENTER);
contentPane.add(jToolBar, BorderLayout.NORTH);
jToolBar.add(jLabel1, null);
jToolBar.add(jTextArea2, null);
jToolBar.add(jLabel2, null);
jToolBar.add(jTextArea3, null);
jToolBar.add(jLabel3, null);
jToolBar.add(jTextArea4, null);
this.setJMenuBar(jMenuBar1);
}
public void openFile(String fileName) {
try {
File file = new File(fileName);
int size = (int) file.length();
int chars_read = 0;
FileReader in = new FileReader(file);
char[] data = new char[size];
while (in.ready()) {
chars_read += in.read(data, chars_read, size - chars_read);
}
in.close();
jTextArea1.setText(new String(data, 0, chars_read));
}
catch (IOException e) {
}
}
//File | Exit action performed
public void jMenuFileExit_actionPerformed(ActionEvent e) {
System.exit(0);
}
//Help | About action performed
//Overridden so we can exit when window is closed
protected void processWindowEvent(WindowEvent e) {
super.processWindowEvent(e);
if (e.getID() == WindowEvent.WINDOW_CLOSING) {
jMenuFileExit_actionPerformed(null);
}
}
void jMenuItem1_actionPerformed(ActionEvent e) {
if (JFileChooser.APPROVE_OPTION == jFileChooser1.showSaveDialog(this)) {
openFile(jFileChooser1.getSelectedFile().getPath());
this.repaint();
}
}
void jMenuItem2_actionPerformed(ActionEvent e) {
jTextArea1.setText("");
}
//find
void jMenuItem3_actionPerformed(ActionEvent e) {
String str = jTextArea1.getText();
double t1=Double.parseDouble(jTextArea2.getText());
double t2=Double.parseDouble(jTextArea3.getText());
double step=Double.parseDouble(jTextArea4.getText());
char t[]=str.toCharArray();
int n=0;//记录有几个串
for(int i=0;i<t.length;i++)
{
if(t[i]=='>')
{
n++;
}
}
String s[] = new String[n];
n=-1;
for(int i=0;i<t.length;i++)
{
if(t[i]=='>')
{
n++;
s[n]="";
while(t[i]!='\n')
{
i++;
}
}
if(t[i]=='A' ||t[i]=='C'||t[i]=='G'||t[i]=='T')
{
s[n]+=t[i];
}
}
Serchmax findmax = new Serchmax(s,t1,t2,step);
result.text.setText(findmax.findresult);
result.show(true );
}
}
class Frame_show_jMenuFileExit_ActionAdapter implements ActionListener {
Frame_show adaptee;
Frame_show_jMenuFileExit_ActionAdapter(Frame_show adaptee) {
this.adaptee = adaptee;
}
public void actionPerformed(ActionEvent e) {
adaptee.jMenuFileExit_actionPerformed(e);
}
}
class Frame_show_jMenuItem1_actionAdapter implements java.awt.event.ActionListener {
Frame_show adaptee;
Frame_show_jMenuItem1_actionAdapter(Frame_show adaptee) {
this.adaptee = adaptee;
}
public void actionPerformed(ActionEvent e) {
adaptee.jMenuItem1_actionPerformed(e);
}
}
class Frame_show_jMenuItem2_actionAdapter implements java.awt.event.ActionListener {
Frame_show adaptee;
Frame_show_jMenuItem2_actionAdapter(Frame_show adaptee) {
this.adaptee = adaptee;
}
public void actionPerformed(ActionEvent e) {
adaptee.jMenuItem2_actionPerformed(e);
}
}
class MyWindow
extends Frame {
TextArea text;
MyWindow(String s) {
super(s);
this.setSize(new Dimension(400, 400));
this.move(400, 200);
setLayout(new GridLayout(1, 1));
text = new TextArea("", 100, 300);
add(text);
setVisible(false);
addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent e) {
setVisible(false);
}
});
}
}
class Frame_show_jMenuItem3_actionAdapter implements java.awt.event.ActionListener {
Frame_show adaptee;
Frame_show_jMenuItem3_actionAdapter(Frame_show adaptee) {
this.adaptee = adaptee;
}
public void actionPerformed(ActionEvent e) {
adaptee.jMenuItem3_actionPerformed(e);
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -