Advertisement
Guest User

Untitled

a guest
Oct 20th, 2019
126
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.78 KB | None | 0 0
  1. // Dit is een Swing applicatie met een ingebouwde filereader. Althans, dat is het idee.
  2.  
  3. import java.awt.*;
  4. import java.awt.event.ActionEvent;
  5. import java.awt.event.ActionListener;
  6. import java.io.File;
  7. //import java.nio.file.FileSystem;
  8. //import java.nio.file.FileSystems;
  9. //import java.nio.file.Path;
  10. //import java.nio.file.Paths;
  11. import javax.swing.*;
  12.  
  13. public class GCApplet extends JFrame {
  14. private JPanel panel;
  15. private JButton browse_button; private JButton read_button;
  16. private JTextField path_field; private JTextField info_field; private JTextField polar_field; private JTextField apolar_field;
  17. private JLabel title; private JLabel file_label; private JLabel info_label; private JLabel percentage_label;
  18.  
  19. public static void main(String[] args) {
  20. SwingUtilities.invokeLater(GCApplet::new); //Schijnbaar volgens "PEP8"
  21. // SwingUtilities.invokeLater(new Runnable() { //Verkeerd volgens "PEP8"
  22. // @Override
  23. // public void run() { new GCApplet(); }
  24. // });
  25. }
  26.  
  27. public static class Polarity {
  28. final String[] POLAR = {"R", "N", "D", "C", "Q", "E", "H", "k", "S", "T", "Y" };
  29. final String[] APOLAR = {"A", "G", "I", "L", "M", "F", "P", "W", "V"};
  30. }
  31.  
  32. private GCApplet() {
  33. JPanel panel = new JPanel();
  34. panel.setLayout(new GridBagLayout());
  35. GridBagConstraints gbc = new GridBagConstraints();
  36. gbc.fill = GridBagConstraints.HORIZONTAL;
  37. gbc.weightx = 1;
  38. gbc.insets = new Insets(5, 5, 5, 5);
  39.  
  40. // laag 0: title
  41. gbc.gridx = 0; gbc.gridy = 0;
  42. JLabel title = new JLabel("this is an amino-acid ");
  43. panel.add(title, gbc);
  44.  
  45.  
  46. // laag 1: path + file buttons
  47. gbc.gridx = 0; gbc.gridy = 1;
  48. JLabel file_label = new JLabel("chosen file path:"); panel.add(file_label, gbc);
  49. gbc.gridx = 1; gbc.gridy = 1;
  50. path_field = new JTextField(); path_field.setPreferredSize(new Dimension(240, 24)); panel.add(path_field, gbc);
  51. gbc.gridx = 2; gbc.gridy = 1;
  52. JButton browse_button = new JButton("browse files");
  53. browse_button.addActionListener(new ActionListener() {
  54. @Override
  55. public void actionPerformed(ActionEvent e) {
  56. System.out.println("let's browse!");
  57. path_field.setText("");
  58. selectFile();
  59. }
  60. });
  61. panel.add(browse_button, gbc);
  62. gbc.gridx = 3; gbc.gridy = 1;
  63. JButton analyse_button = new JButton("analyse file");
  64. panel.add(analyse_button, gbc);
  65.  
  66. // laag 2: info + summary textfield
  67. gbc.gridx = 0; gbc.gridy = 2;
  68. JLabel info_label = new JLabel("total file info:"); panel.add(info_label, gbc);
  69. gbc.gridx = 1; gbc.gridy = 2; gbc.gridwidth = 3;
  70. JTextArea info_field = new JTextArea();
  71. info_field.setPreferredSize(new Dimension(180, 100));
  72. info_field.setLineWrap(true); info_field.setWrapStyleWord(true);
  73. panel.add(info_field, gbc);
  74.  
  75. // laag 3 + 4: percentage uitdrukkingen
  76. gbc.gridx = 0; gbc.gridy = 3;
  77. JLabel perc_label = new JLabel("percentages:"); panel.add(perc_label, gbc);
  78. gbc.gridx = 1; gbc.gridy = 3; gbc.gridwidth = 2;
  79. JTextField polar_field = new JTextField(); polar_field.setPreferredSize(new Dimension(180, 24)); panel.add(polar_field, gbc);
  80. gbc.gridx = 1; gbc.gridy = 4; gbc.gridwidth = 2;
  81. JTextField apolar_field = new JTextField(); apolar_field.setPreferredSize(new Dimension(180, 24)); panel.add(apolar_field, gbc);
  82.  
  83. // Frame aanmaken en panel met applicaties toevoegen aan frame.
  84. JFrame frame = new JFrame();
  85. frame.setTitle("Amino-acid analysis app");
  86. frame.add(panel); frame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
  87. frame.pack(); frame.setVisible(true);
  88.  
  89. System.out.println(" I just made this! proud :)");
  90. }
  91.  
  92. private String selectFile() {
  93. System.out.println("Laat ik een file gaan openen");
  94.  
  95. // Selecting file and getting filePath
  96. String filePath = "";
  97. JFileChooser fileChooser = new JFileChooser();
  98. int returnValue = fileChooser.showOpenDialog(null);
  99. if (returnValue == JFileChooser.APPROVE_OPTION) {
  100. File selectedFile = fileChooser.getSelectedFile();
  101. filePath = selectedFile.getPath();
  102. System.out.println(filePath);
  103. path_field.setText(selectedFile.getPath());
  104. path_field.setVisible(true);
  105. } else {
  106. System.out.println("nope, shit happened");}
  107. return filePath;
  108. }
  109.  
  110. private String analyze_file() {
  111. String file_to_analyse = filePath;
  112. return "asdf";
  113. }
  114.  
  115. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement