Advertisement
Guest User

Untitled

a guest
Mar 21st, 2018
62
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 11.49 KB | None | 0 0
  1. /*
  2. * To change this license header, choose License Headers in Project Properties.
  3. * To change this template file, choose Tools | Templates
  4. * and open the template in the editor.
  5. */
  6. package matrix;
  7.  
  8. import java.util.concurrent.TimeUnit;
  9. import java.sql.Timestamp;
  10. import java.io.PrintWriter;
  11. import java.io.FileWriter;
  12. import java.io.IOException;
  13. import java.util.logging.Level;
  14. import java.util.logging.Logger;
  15. /**
  16. *
  17. * @author Jan
  18. */
  19. public class gui extends javax.swing.JFrame {
  20.  
  21. static Led c;
  22. String pfad;
  23.  
  24. /**
  25. * Creates new form gui
  26. */
  27. public gui() {
  28. initComponents();
  29. }
  30.  
  31. /**
  32. * This method is called from within the constructor to initialize the form.
  33. * WARNING: Do NOT modify this code. The content of this method is always
  34. * regenerated by the Form Editor.
  35. */
  36. @SuppressWarnings("unchecked")
  37. // <editor-fold defaultstate="collapsed" desc="Generated Code">
  38. private void initComponents() {
  39.  
  40. ledLabel = new javax.swing.JLabel();
  41. nachrichtFeld = new javax.swing.JTextField();
  42. dauersendenCheckBox = new javax.swing.JCheckBox();
  43. sendenBtn = new javax.swing.JButton();
  44. stoppenBtn = new javax.swing.JButton();
  45. pfadFeld = new javax.swing.JTextField();
  46. pfadLabel = new javax.swing.JLabel();
  47. pfadBtn = new javax.swing.JButton();
  48. winkelFeld = new javax.swing.JTextField();
  49. winkelLabel = new javax.swing.JLabel();
  50. winkelBtn = new javax.swing.JButton();
  51.  
  52. setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
  53.  
  54. ledLabel.setFont(new java.awt.Font("Tahoma", 1, 24)); // NOI18N
  55. ledLabel.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
  56. ledLabel.setText("LED Matrix - An und Abwesenheitsinfo");
  57.  
  58. nachrichtFeld.setText("Text");
  59.  
  60. dauersendenCheckBox.setSelected(true);
  61. dauersendenCheckBox.setText("Dauersenden");
  62.  
  63. sendenBtn.setText("Senden");
  64. sendenBtn.addActionListener(new java.awt.event.ActionListener() {
  65. public void actionPerformed(java.awt.event.ActionEvent evt) {
  66. sendenBtnActionPerformed(evt);
  67. }
  68. });
  69.  
  70. stoppenBtn.setText("Stoppen");
  71. stoppenBtn.addActionListener(new java.awt.event.ActionListener() {
  72. public void actionPerformed(java.awt.event.ActionEvent evt) {
  73. stoppenBtnActionPerformed(evt);
  74. }
  75. });
  76.  
  77. pfadFeld.setText("/home/pi/TextLog.txt");
  78.  
  79. pfadLabel.setText("Pfad der Log - Datei");
  80.  
  81. pfadBtn.setText("Setzen");
  82. pfadBtn.addActionListener(new java.awt.event.ActionListener() {
  83. public void actionPerformed(java.awt.event.ActionEvent evt) {
  84. pfadBtnActionPerformed(evt);
  85. }
  86. });
  87.  
  88. winkelFeld.setText("90");
  89.  
  90. winkelLabel.setText("Winkel der Anzeige (90, 180, 270)");
  91.  
  92. winkelBtn.setText("Setzen");
  93. winkelBtn.addActionListener(new java.awt.event.ActionListener() {
  94. public void actionPerformed(java.awt.event.ActionEvent evt) {
  95. winkelBtnActionPerformed(evt);
  96. }
  97. });
  98.  
  99. javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
  100. getContentPane().setLayout(layout);
  101. layout.setHorizontalGroup(
  102. layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
  103. .addGroup(layout.createSequentialGroup()
  104. .addContainerGap()
  105. .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
  106. .addComponent(ledLabel, javax.swing.GroupLayout.DEFAULT_SIZE, 482, Short.MAX_VALUE)
  107. .addGroup(layout.createSequentialGroup()
  108. .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
  109. .addComponent(winkelFeld, javax.swing.GroupLayout.Alignment.LEADING)
  110. .addComponent(pfadFeld, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 300, Short.MAX_VALUE)
  111. .addComponent(nachrichtFeld, javax.swing.GroupLayout.Alignment.LEADING))
  112. .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
  113. .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
  114. .addComponent(dauersendenCheckBox, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
  115. .addComponent(pfadLabel, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
  116. .addComponent(winkelLabel, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)))
  117. .addGroup(layout.createSequentialGroup()
  118. .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
  119. .addGroup(layout.createSequentialGroup()
  120. .addComponent(sendenBtn, javax.swing.GroupLayout.PREFERRED_SIZE, 85, javax.swing.GroupLayout.PREFERRED_SIZE)
  121. .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
  122. .addComponent(stoppenBtn, javax.swing.GroupLayout.PREFERRED_SIZE, 85, javax.swing.GroupLayout.PREFERRED_SIZE))
  123. .addComponent(pfadBtn)
  124. .addComponent(winkelBtn))
  125. .addGap(0, 0, Short.MAX_VALUE)))
  126. .addContainerGap())
  127. );
  128. layout.setVerticalGroup(
  129. layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
  130. .addGroup(layout.createSequentialGroup()
  131. .addContainerGap()
  132. .addComponent(ledLabel, javax.swing.GroupLayout.PREFERRED_SIZE, 42, javax.swing.GroupLayout.PREFERRED_SIZE)
  133. .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
  134. .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
  135. .addComponent(nachrichtFeld, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
  136. .addComponent(dauersendenCheckBox))
  137. .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
  138. .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
  139. .addComponent(sendenBtn)
  140. .addComponent(stoppenBtn))
  141. .addGap(18, 18, 18)
  142. .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
  143. .addComponent(pfadFeld, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
  144. .addComponent(pfadLabel))
  145. .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
  146. .addComponent(pfadBtn)
  147. .addGap(18, 18, 18)
  148. .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
  149. .addComponent(winkelFeld, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
  150. .addComponent(winkelLabel))
  151. .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
  152. .addComponent(winkelBtn)
  153. .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
  154. );
  155.  
  156. pack();
  157. }// </editor-fold>
  158.  
  159. private void sendenBtnActionPerformed(java.awt.event.ActionEvent evt) {
  160.  
  161. String timestamp = new Timestamp(System.currentTimeMillis()).toString();
  162. String nachricht = nachrichtFeld.getText();
  163.  
  164. try(PrintWriter out = new PrintWriter(new FileWriter(pfadFeld.getText(), true));){
  165.  
  166. out.println(nachricht+" || ausgegeben am: "+timestamp);
  167. } catch (IOException ex) {
  168. Logger.getLogger(gui.class.getName()).log(Level.SEVERE, null, ex);
  169. }
  170.  
  171. if(dauersendenCheckBox.isEnabled()){
  172. while(true){
  173. c.showMessage(nachricht);
  174. try {
  175. TimeUnit.SECONDS.sleep(3);
  176. } catch (InterruptedException ex) {
  177. Logger.getLogger(gui.class.getName()).log(Level.SEVERE, null, ex);
  178. }
  179. }
  180. }
  181. else{
  182. c.showMessage(nachricht);
  183. }
  184. }
  185.  
  186. private void stoppenBtnActionPerformed(java.awt.event.ActionEvent evt) {
  187. c.flush();
  188. }
  189.  
  190. private void pfadBtnActionPerformed(java.awt.event.ActionEvent evt) {
  191. pfad = pfadFeld.getText();
  192. }
  193.  
  194. private void winkelBtnActionPerformed(java.awt.event.ActionEvent evt) {
  195.  
  196. int winkel = Integer.parseInt(winkelFeld.getText());
  197. c.orientation(winkel);
  198. }
  199.  
  200. /**
  201. * @param args the command line arguments
  202. */
  203. public static void main(String args[]) {
  204.  
  205. c = new Led((short)4);
  206. c.open();
  207.  
  208. try {
  209. for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
  210. if ("Windows".equals(info.getName())) {
  211. javax.swing.UIManager.setLookAndFeel(info.getClassName());
  212. break;
  213. }
  214. }
  215. } catch (ClassNotFoundException ex) {
  216. java.util.logging.Logger.getLogger(gui.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
  217. } catch (InstantiationException ex) {
  218. java.util.logging.Logger.getLogger(gui.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
  219. } catch (IllegalAccessException ex) {
  220. java.util.logging.Logger.getLogger(gui.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
  221. } catch (javax.swing.UnsupportedLookAndFeelException ex) {
  222. java.util.logging.Logger.getLogger(gui.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
  223. }
  224.  
  225. java.awt.EventQueue.invokeLater(new Runnable() {
  226. public void run() {
  227. new gui().setVisible(true);
  228. }
  229. });
  230. }
  231.  
  232. // Variables declaration - do not modify
  233. private javax.swing.JCheckBox dauersendenCheckBox;
  234. private javax.swing.JLabel ledLabel;
  235. private javax.swing.JTextField nachrichtFeld;
  236. private javax.swing.JButton pfadBtn;
  237. private javax.swing.JTextField pfadFeld;
  238. private javax.swing.JLabel pfadLabel;
  239. private javax.swing.JButton sendenBtn;
  240. private javax.swing.JButton stoppenBtn;
  241. private javax.swing.JButton winkelBtn;
  242. private javax.swing.JTextField winkelFeld;
  243. private javax.swing.JLabel winkelLabel;
  244. // End of variables declaration
  245. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement