Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- * To change this license header, choose License Headers in Project Properties.
- * To change this template file, choose Tools | Templates
- * and open the template in the editor.
- */
- package matrix;
- import java.util.concurrent.TimeUnit;
- import java.sql.Timestamp;
- import java.io.PrintWriter;
- import java.io.FileWriter;
- import java.io.IOException;
- import java.util.logging.Level;
- import java.util.logging.Logger;
- /**
- *
- * @author Jan
- */
- public class gui extends javax.swing.JFrame {
- static Led c;
- String pfad;
- /**
- * Creates new form gui
- */
- public gui() {
- initComponents();
- }
- /**
- * This method is called from within the constructor to initialize the form.
- * WARNING: Do NOT modify this code. The content of this method is always
- * regenerated by the Form Editor.
- */
- @SuppressWarnings("unchecked")
- // <editor-fold defaultstate="collapsed" desc="Generated Code">
- private void initComponents() {
- ledLabel = new javax.swing.JLabel();
- nachrichtFeld = new javax.swing.JTextField();
- dauersendenCheckBox = new javax.swing.JCheckBox();
- sendenBtn = new javax.swing.JButton();
- stoppenBtn = new javax.swing.JButton();
- pfadFeld = new javax.swing.JTextField();
- pfadLabel = new javax.swing.JLabel();
- pfadBtn = new javax.swing.JButton();
- winkelFeld = new javax.swing.JTextField();
- winkelLabel = new javax.swing.JLabel();
- winkelBtn = new javax.swing.JButton();
- setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
- ledLabel.setFont(new java.awt.Font("Tahoma", 1, 24)); // NOI18N
- ledLabel.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
- ledLabel.setText("LED Matrix - An und Abwesenheitsinfo");
- nachrichtFeld.setText("Text");
- dauersendenCheckBox.setSelected(true);
- dauersendenCheckBox.setText("Dauersenden");
- sendenBtn.setText("Senden");
- sendenBtn.addActionListener(new java.awt.event.ActionListener() {
- public void actionPerformed(java.awt.event.ActionEvent evt) {
- sendenBtnActionPerformed(evt);
- }
- });
- stoppenBtn.setText("Stoppen");
- stoppenBtn.addActionListener(new java.awt.event.ActionListener() {
- public void actionPerformed(java.awt.event.ActionEvent evt) {
- stoppenBtnActionPerformed(evt);
- }
- });
- pfadFeld.setText("/home/pi/TextLog.txt");
- pfadLabel.setText("Pfad der Log - Datei");
- pfadBtn.setText("Setzen");
- pfadBtn.addActionListener(new java.awt.event.ActionListener() {
- public void actionPerformed(java.awt.event.ActionEvent evt) {
- pfadBtnActionPerformed(evt);
- }
- });
- winkelFeld.setText("90");
- winkelLabel.setText("Winkel der Anzeige (90, 180, 270)");
- winkelBtn.setText("Setzen");
- winkelBtn.addActionListener(new java.awt.event.ActionListener() {
- public void actionPerformed(java.awt.event.ActionEvent evt) {
- winkelBtnActionPerformed(evt);
- }
- });
- javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
- getContentPane().setLayout(layout);
- layout.setHorizontalGroup(
- layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
- .addGroup(layout.createSequentialGroup()
- .addContainerGap()
- .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
- .addComponent(ledLabel, javax.swing.GroupLayout.DEFAULT_SIZE, 482, Short.MAX_VALUE)
- .addGroup(layout.createSequentialGroup()
- .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
- .addComponent(winkelFeld, javax.swing.GroupLayout.Alignment.LEADING)
- .addComponent(pfadFeld, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 300, Short.MAX_VALUE)
- .addComponent(nachrichtFeld, javax.swing.GroupLayout.Alignment.LEADING))
- .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
- .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
- .addComponent(dauersendenCheckBox, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
- .addComponent(pfadLabel, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
- .addComponent(winkelLabel, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)))
- .addGroup(layout.createSequentialGroup()
- .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
- .addGroup(layout.createSequentialGroup()
- .addComponent(sendenBtn, javax.swing.GroupLayout.PREFERRED_SIZE, 85, javax.swing.GroupLayout.PREFERRED_SIZE)
- .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
- .addComponent(stoppenBtn, javax.swing.GroupLayout.PREFERRED_SIZE, 85, javax.swing.GroupLayout.PREFERRED_SIZE))
- .addComponent(pfadBtn)
- .addComponent(winkelBtn))
- .addGap(0, 0, Short.MAX_VALUE)))
- .addContainerGap())
- );
- layout.setVerticalGroup(
- layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
- .addGroup(layout.createSequentialGroup()
- .addContainerGap()
- .addComponent(ledLabel, javax.swing.GroupLayout.PREFERRED_SIZE, 42, javax.swing.GroupLayout.PREFERRED_SIZE)
- .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
- .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
- .addComponent(nachrichtFeld, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
- .addComponent(dauersendenCheckBox))
- .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
- .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
- .addComponent(sendenBtn)
- .addComponent(stoppenBtn))
- .addGap(18, 18, 18)
- .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
- .addComponent(pfadFeld, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
- .addComponent(pfadLabel))
- .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
- .addComponent(pfadBtn)
- .addGap(18, 18, 18)
- .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
- .addComponent(winkelFeld, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
- .addComponent(winkelLabel))
- .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
- .addComponent(winkelBtn)
- .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
- );
- pack();
- }// </editor-fold>
- private void sendenBtnActionPerformed(java.awt.event.ActionEvent evt) {
- String timestamp = new Timestamp(System.currentTimeMillis()).toString();
- String nachricht = nachrichtFeld.getText();
- try(PrintWriter out = new PrintWriter(new FileWriter(pfadFeld.getText(), true));){
- out.println(nachricht+" || ausgegeben am: "+timestamp);
- } catch (IOException ex) {
- Logger.getLogger(gui.class.getName()).log(Level.SEVERE, null, ex);
- }
- if(dauersendenCheckBox.isEnabled()){
- while(true){
- c.showMessage(nachricht);
- try {
- TimeUnit.SECONDS.sleep(3);
- } catch (InterruptedException ex) {
- Logger.getLogger(gui.class.getName()).log(Level.SEVERE, null, ex);
- }
- }
- }
- else{
- c.showMessage(nachricht);
- }
- }
- private void stoppenBtnActionPerformed(java.awt.event.ActionEvent evt) {
- c.flush();
- }
- private void pfadBtnActionPerformed(java.awt.event.ActionEvent evt) {
- pfad = pfadFeld.getText();
- }
- private void winkelBtnActionPerformed(java.awt.event.ActionEvent evt) {
- int winkel = Integer.parseInt(winkelFeld.getText());
- c.orientation(winkel);
- }
- /**
- * @param args the command line arguments
- */
- public static void main(String args[]) {
- c = new Led((short)4);
- c.open();
- try {
- for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
- if ("Windows".equals(info.getName())) {
- javax.swing.UIManager.setLookAndFeel(info.getClassName());
- break;
- }
- }
- } catch (ClassNotFoundException ex) {
- java.util.logging.Logger.getLogger(gui.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
- } catch (InstantiationException ex) {
- java.util.logging.Logger.getLogger(gui.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
- } catch (IllegalAccessException ex) {
- java.util.logging.Logger.getLogger(gui.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
- } catch (javax.swing.UnsupportedLookAndFeelException ex) {
- java.util.logging.Logger.getLogger(gui.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
- }
- java.awt.EventQueue.invokeLater(new Runnable() {
- public void run() {
- new gui().setVisible(true);
- }
- });
- }
- // Variables declaration - do not modify
- private javax.swing.JCheckBox dauersendenCheckBox;
- private javax.swing.JLabel ledLabel;
- private javax.swing.JTextField nachrichtFeld;
- private javax.swing.JButton pfadBtn;
- private javax.swing.JTextField pfadFeld;
- private javax.swing.JLabel pfadLabel;
- private javax.swing.JButton sendenBtn;
- private javax.swing.JButton stoppenBtn;
- private javax.swing.JButton winkelBtn;
- private javax.swing.JTextField winkelFeld;
- private javax.swing.JLabel winkelLabel;
- // End of variables declaration
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement