Hallo zusammen,
ich bin noch sehr neu in Java und versuche derzeit für ein bestimmtes Programm meines Arduino Unos eine GUI zu programmieren (mit Eclipse). Ich verwende als zusätzliche Library für Eclipse diese hier. Meine Breakpoints im Eventhandler (Test1, Test2) werden nie ausgeführt, egal was ich tue. Demnach vermute ich, dass es am EventHandler/Listener liegt, aber ich habe keine Idee was es genau ist. Hier ist mein Code:
Ich hoffe, dass mir jemand helfen kann
Sketch
ich bin noch sehr neu in Java und versuche derzeit für ein bestimmtes Programm meines Arduino Unos eine GUI zu programmieren (mit Eclipse). Ich verwende als zusätzliche Library für Eclipse diese hier. Meine Breakpoints im Eventhandler (Test1, Test2) werden nie ausgeführt, egal was ich tue. Demnach vermute ich, dass es am EventHandler/Listener liegt, aber ich habe keine Idee was es genau ist. Hier ist mein Code:
Java:
package main;
import java.awt.event.ItemEvent;
import java.awt.event.ItemListener;
import java.io.PrintWriter;
import javax.swing.DefaultComboBoxModel;
import javax.swing.GroupLayout;
import javax.swing.GroupLayout.Alignment;
import javax.swing.JComboBox;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.LayoutStyle.ComponentPlacement;
import javax.swing.WindowConstants;
import javax.swing.plaf.basic.BasicComboBoxUI;
import javax.swing.plaf.basic.BasicComboBoxUI.ItemHandler;
public class GUI extends JPanel
{
static GUI gui = new GUI();
public static void GUImain()
{
gui.GUI();
}
private static final long serialVersionUID = 1L;
static int baudRate = 9600;
public BasicComboBoxUI bcbu = new BasicComboBoxUI();
static PrintWriter outPut;
public javax.swing.plaf.basic.BasicComboBoxUI.ItemHandler handler = bcbu.new ItemHandler();
public JComboBox comboBox = new JComboBox();
public JComboBox comboBox_1 = new JComboBox();
public JComboBox comboBox_2 = new JComboBox();
public JComboBox comboBox_3 = new JComboBox();
public JFrame startseite = new JFrame();
public JLabel lblNewLabel = new JLabel("Runner left-right");
public JLabel lblPulseInout = new JLabel("Pulse in-out");
public JLabel lblRunnerRightleft = new JLabel("Runner right-left");
public JLabel lblPulseOutin = new JLabel("Pulse out-in");
public void GUI() {
setToolTipText("Arduino Lightshow Control - ");
//setLayout(null);
JPanel panel = new JPanel();
panel.setToolTipText("Arduino Lightshow Control");
comboBox.setModel(new DefaultComboBoxModel(new String[] {"1", "2", "3", "4", "5"}));
comboBox.setToolTipText("Runner left-right");
comboBox.addItemListener(handler);
comboBox_1.setModel(new DefaultComboBoxModel(new String[] {"1", "2", "3", "4", "5"}));
comboBox_1.setToolTipText("Runner right-left");
comboBox_1.addItemListener(handler);
comboBox_2.setModel(new DefaultComboBoxModel(new String[] {"1", "2", "3", "4", "5"}));
comboBox_2.setToolTipText("Pulse in-out");
comboBox_2.addItemListener(handler);
comboBox_3.setModel(new DefaultComboBoxModel(new String[] {"1", "2", "3", "4", "5"}));
comboBox_3.setToolTipText("Pulse out-in");
comboBox_3.addItemListener(handler);
startseite.setVisible(true);
startseite.setTitle("Arduino Lightshow Control");
startseite.setSize(450, 300);
startseite.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
GroupLayout groupLayout = new GroupLayout(startseite.getContentPane());
groupLayout.setHorizontalGroup(
groupLayout.createParallelGroup(Alignment.LEADING)
.addComponent(panel, GroupLayout.PREFERRED_SIZE, 434, GroupLayout.PREFERRED_SIZE)
);
groupLayout.setVerticalGroup(
groupLayout.createParallelGroup(Alignment.LEADING)
.addComponent(panel, GroupLayout.PREFERRED_SIZE, 261, GroupLayout.PREFERRED_SIZE)
);
GroupLayout gl_panel = new GroupLayout(panel);
gl_panel.setHorizontalGroup(
gl_panel.createParallelGroup(Alignment.LEADING)
.addGroup(gl_panel.createSequentialGroup()
.addGap(32)
.addGroup(gl_panel.createParallelGroup(Alignment.LEADING)
.addComponent(lblPulseOutin)
.addComponent(comboBox_3, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)
.addComponent(comboBox, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)
.addComponent(lblNewLabel))
.addGap(210)
.addGroup(gl_panel.createParallelGroup(Alignment.LEADING)
.addComponent(lblRunnerRightleft)
.addComponent(comboBox_1, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)
.addComponent(comboBox_2, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)
.addComponent(lblPulseInout))
.addGap(32))
);
gl_panel.setVerticalGroup(
gl_panel.createParallelGroup(Alignment.LEADING)
.addGroup(gl_panel.createSequentialGroup()
.addContainerGap()
.addGroup(gl_panel.createParallelGroup(Alignment.BASELINE)
.addComponent(lblNewLabel)
.addComponent(lblRunnerRightleft))
.addPreferredGap(ComponentPlacement.RELATED)
.addGroup(gl_panel.createParallelGroup(Alignment.BASELINE)
.addComponent(comboBox_1, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)
.addComponent(comboBox, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE))
.addGap(23)
.addGroup(gl_panel.createParallelGroup(Alignment.BASELINE)
.addComponent(lblPulseOutin)
.addComponent(lblPulseInout))
.addGap(13)
.addGroup(gl_panel.createParallelGroup(Alignment.BASELINE)
.addComponent(comboBox_3, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)
.addComponent(comboBox_2, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE))
.addContainerGap(137, Short.MAX_VALUE))
);
panel.setLayout(gl_panel);
startseite.getContentPane().setLayout(groupLayout);
}
private class ItemHandler implements ItemListener{
@Override
public void itemStateChanged(ItemEvent event)
{
if(event.getSource() == comboBox)
{
if(comboBox.getSelectedItem().equals("1"))
{
System.out.println("Test1");
outPut.print("RLR1");
outPut.flush();
}
else if(comboBox.getSelectedItem().equals("2"))
{
System.out.println("Test2");
outPut.print("RLR2");
outPut.flush();
}
if(comboBox.getSelectedItem().equals("3"))
{
outPut.print("RLR3");
outPut.flush();
}
else if(comboBox.getSelectedItem().equals("4"))
{
outPut.print("RLR4");
outPut.flush();
}
else if(comboBox.getSelectedItem().equals("5"))
{
outPut.print("RLR5");
outPut.flush();
}
}
else if(event.getSource() == comboBox_1)
{
if(comboBox_1.getSelectedItem().equals("1"))
{
outPut.print("RRL1");
outPut.flush();
}
else if(comboBox_1.getSelectedItem().equals("2"))
{
outPut.print("RRL2");
outPut.flush();
}
if(comboBox_1.getSelectedItem().equals("3"))
{
outPut.print("RRL3");
outPut.flush();
}
else if(comboBox_1.getSelectedItem().equals("4"))
{
outPut.print("RRL4");
outPut.flush();
}
else if(comboBox_1.getSelectedItem().equals("5"))
{
outPut.print("RRL5");
outPut.flush();
}
}
else if(event.getSource() == comboBox_2)
{
if(comboBox_2.getSelectedItem().equals("1"))
{
outPut.print("IO1");
outPut.flush();
}
else if(comboBox_2.getSelectedItem().equals("2"))
{
outPut.print("IO2");
outPut.flush();
}
if(comboBox_2.getSelectedItem().equals("3"))
{
outPut.print("IO3");
outPut.flush();
}
else if(comboBox_2.getSelectedItem().equals("4"))
{
outPut.print("IO4");
outPut.flush();
}
else if(comboBox_2.getSelectedItem().equals("5"))
{
outPut.print("IO5");
outPut.flush();
}
}
else if(event.getSource() == comboBox_3)
{
if(comboBox_3.getSelectedItem().equals("1"))
{
outPut.print("OI1");
outPut.flush();
}
else if(comboBox_3.getSelectedItem().equals("2"))
{
outPut.print("OI2");
outPut.flush();
}
if(comboBox_3.getSelectedItem().equals("3"))
{
outPut.print("OI3");
outPut.flush();
}
else if(comboBox_3.getSelectedItem().equals("4"))
{
outPut.print("OI4");
outPut.flush();
}
else if(comboBox_3.getSelectedItem().equals("5"))
{
outPut.print("OI5");
outPut.flush();
}
}
}
}
}
Ich hoffe, dass mir jemand helfen kann
Sketch