Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /**
- * @(#)GUI.java
- *
- *
- * @Filbert Nicholas
- * @version 1.00 2014/7/9
- */
- import java.io.*;
- import java.awt.*;
- import java.awt.event.*;
- import javax.swing.*;
- //import javax.swing.filechooser.*;
- public class GUI extends JFrame implements ActionListener {
- private Label lbl;
- public TextField tf;
- private Button bwsbtn, idbtn;
- public String path;
- File selectedFile;
- // Constructor to setup GUI components and event handling
- public GUI() {
- setLayout(null);
- setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
- setTitle("File Fragment Identifier");
- setSize(300,150);
- setVisible(true);
- setResizable(false);
- lbl = new Label("Input File Fragment");
- add(lbl);
- lbl.setBounds(55,5,200,25);
- lbl.setFont(new Font("Arial", Font.PLAIN, 20));
- tf = new TextField("");
- add(tf);
- tf.setBounds(25,35,225,25);
- bwsbtn = new Button("Browse");
- add(bwsbtn);
- bwsbtn.addActionListener(this);
- bwsbtn.setBounds(25,70,110,35);
- idbtn = new Button("Identify");
- add(idbtn);
- idbtn.addActionListener(this);
- idbtn.setBounds(155,70,110,35);
- }
- public void actionPerformed(ActionEvent e){
- //Handle browse event
- try{
- if(e.getSource() == bwsbtn){
- JFileChooser fc = new JFileChooser();
- fc.setFileSelectionMode(JFileChooser.FILES_ONLY);
- int returnVal = fc.showOpenDialog(GUI.this);
- if(returnVal == JFileChooser.APPROVE_OPTION){
- selectedFile = fc.getSelectedFile();
- path = selectedFile.getAbsolutePath();
- tf.setText(selectedFile + ".");
- }else{
- JOptionPane.showMessageDialog(null, "Please choose a file.");
- }
- }
- //Handle identify button
- if(e.getSource() == idbtn){
- if(tf.getText().equals("")){
- JOptionPane.showMessageDialog(null,"Please select fragment file.");
- }else{
- try{
- long startpx = 0;
- long startpy = 0;
- long readSize = 2048;
- String temp = "";
- while(true){
- StringResult sr = new StringResult();
- String x = LCSf.readFile("D:\\TA\\Skripsi\\PDF.txt", startpx, readSize);
- String y = LCSf.GenStr2(selectedFile, startpy, readSize);
- temp = temp + sr.Compare(x, y);
- if(sr.posx == -1 && sr.posy == -1){
- startpx = startpx + readSize;
- startpy = startpy + readSize;
- }
- else{
- startpx += sr.posx + 1;
- startpy += sr.posy + 1;
- }
- System.out.println(sr.posx);
- if(startpx > "D:\\TA\\Skripsi\\PDF.txt".length()){
- System.out.println("LCS: " + temp);
- System.out.println("Length: " + temp.length());
- break;
- }
- if(startpy > selectedFile.length()){
- System.out.println("LCS: " + temp);
- System.out.println("Length: " + temp.length());
- break;
- }
- }
- }finally{
- }
- }
- }
- }catch(IOException f){
- }
- finally{
- }
- }
- public static void main (String[] args){
- GUI app = new GUI();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement