Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Dit is een Swing applicatie met een ingebouwde filereader. Althans, dat is het idee.
- import java.awt.*;
- import java.awt.event.ActionEvent;
- import java.awt.event.ActionListener;
- import java.io.File;
- //import java.nio.file.FileSystem;
- //import java.nio.file.FileSystems;
- //import java.nio.file.Path;
- //import java.nio.file.Paths;
- import javax.swing.*;
- public class GCApplet extends JFrame {
- private JPanel panel;
- private JButton browse_button; private JButton read_button;
- private JTextField path_field; private JTextField info_field; private JTextField polar_field; private JTextField apolar_field;
- private JLabel title; private JLabel file_label; private JLabel info_label; private JLabel percentage_label;
- public static void main(String[] args) {
- SwingUtilities.invokeLater(GCApplet::new); //Schijnbaar volgens "PEP8"
- // SwingUtilities.invokeLater(new Runnable() { //Verkeerd volgens "PEP8"
- // @Override
- // public void run() { new GCApplet(); }
- // });
- }
- public static class Polarity {
- final String[] POLAR = {"R", "N", "D", "C", "Q", "E", "H", "k", "S", "T", "Y" };
- final String[] APOLAR = {"A", "G", "I", "L", "M", "F", "P", "W", "V"};
- }
- private GCApplet() {
- JPanel panel = new JPanel();
- panel.setLayout(new GridBagLayout());
- GridBagConstraints gbc = new GridBagConstraints();
- gbc.fill = GridBagConstraints.HORIZONTAL;
- gbc.weightx = 1;
- gbc.insets = new Insets(5, 5, 5, 5);
- // laag 0: title
- gbc.gridx = 0; gbc.gridy = 0;
- JLabel title = new JLabel("this is an amino-acid ");
- panel.add(title, gbc);
- // laag 1: path + file buttons
- gbc.gridx = 0; gbc.gridy = 1;
- JLabel file_label = new JLabel("chosen file path:"); panel.add(file_label, gbc);
- gbc.gridx = 1; gbc.gridy = 1;
- path_field = new JTextField(); path_field.setPreferredSize(new Dimension(240, 24)); panel.add(path_field, gbc);
- gbc.gridx = 2; gbc.gridy = 1;
- JButton browse_button = new JButton("browse files");
- browse_button.addActionListener(new ActionListener() {
- @Override
- public void actionPerformed(ActionEvent e) {
- System.out.println("let's browse!");
- path_field.setText("");
- selectFile();
- }
- });
- panel.add(browse_button, gbc);
- gbc.gridx = 3; gbc.gridy = 1;
- JButton analyse_button = new JButton("analyse file");
- panel.add(analyse_button, gbc);
- // laag 2: info + summary textfield
- gbc.gridx = 0; gbc.gridy = 2;
- JLabel info_label = new JLabel("total file info:"); panel.add(info_label, gbc);
- gbc.gridx = 1; gbc.gridy = 2; gbc.gridwidth = 3;
- JTextArea info_field = new JTextArea();
- info_field.setPreferredSize(new Dimension(180, 100));
- info_field.setLineWrap(true); info_field.setWrapStyleWord(true);
- panel.add(info_field, gbc);
- // laag 3 + 4: percentage uitdrukkingen
- gbc.gridx = 0; gbc.gridy = 3;
- JLabel perc_label = new JLabel("percentages:"); panel.add(perc_label, gbc);
- gbc.gridx = 1; gbc.gridy = 3; gbc.gridwidth = 2;
- JTextField polar_field = new JTextField(); polar_field.setPreferredSize(new Dimension(180, 24)); panel.add(polar_field, gbc);
- gbc.gridx = 1; gbc.gridy = 4; gbc.gridwidth = 2;
- JTextField apolar_field = new JTextField(); apolar_field.setPreferredSize(new Dimension(180, 24)); panel.add(apolar_field, gbc);
- // Frame aanmaken en panel met applicaties toevoegen aan frame.
- JFrame frame = new JFrame();
- frame.setTitle("Amino-acid analysis app");
- frame.add(panel); frame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
- frame.pack(); frame.setVisible(true);
- System.out.println(" I just made this! proud :)");
- }
- private String selectFile() {
- System.out.println("Laat ik een file gaan openen");
- // Selecting file and getting filePath
- String filePath = "";
- JFileChooser fileChooser = new JFileChooser();
- int returnValue = fileChooser.showOpenDialog(null);
- if (returnValue == JFileChooser.APPROVE_OPTION) {
- File selectedFile = fileChooser.getSelectedFile();
- filePath = selectedFile.getPath();
- System.out.println(filePath);
- path_field.setText(selectedFile.getPath());
- path_field.setVisible(true);
- } else {
- System.out.println("nope, shit happened");}
- return filePath;
- }
- private String analyze_file() {
- String file_to_analyse = filePath;
- return "asdf";
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement