Skip to content
Snippets Groups Projects
Commit 50b40ecc authored by Leon Dieter's avatar Leon Dieter
Browse files

Buttons scalable / window scalable

parent 9aa2d05d
No related branches found
No related tags found
No related merge requests found
...@@ -135,16 +135,16 @@ public class GUI extends JFrame implements Runnable, ActionListener { ...@@ -135,16 +135,16 @@ public class GUI extends JFrame implements Runnable, ActionListener {
@Override @Override
public void componentResized(ComponentEvent e) { public void componentResized(ComponentEvent e) {
if(Math.abs(WindowHeight - getHeight()) > 30 || Math.abs(WindowWidth - getWidth()) > 30) {
System.out.println("boom..");
WindowHeight = getHeight(); WindowHeight = getHeight();
WindowWidth = getWidth(); WindowWidth = getWidth();
topPanelWidth = topPanel.getWidth(); topPanelWidth = topPanel.getWidth();
topPanelHeight = topPanel.getHeight(); topPanelHeight = topPanel.getHeight();
if(topPanelWidth <= ((topPanelHeight + WindowHeight) / 2)) { if(topPanelWidth <= ((topPanelHeight + WindowHeight) / 2)) {
xscale = topPanelWidth; xscale = topPanelWidth;
...@@ -158,7 +158,7 @@ public class GUI extends JFrame implements Runnable, ActionListener { ...@@ -158,7 +158,7 @@ public class GUI extends JFrame implements Runnable, ActionListener {
updateGUI(xscale, yscale); updateGUI(xscale, yscale);
//} //}
}
} }
......
...@@ -26,7 +26,7 @@ import tec.letsgoing.ardublock.simulator.view.GUI; ...@@ -26,7 +26,7 @@ import tec.letsgoing.ardublock.simulator.view.GUI;
*/ */
public class Button extends Modul implements ActionListener { public class Button extends Modul implements ActionListener {
private int[] lastState = { 0, 0, 0 }; private int[] lastState = { 0, 0, 0 };
private ImageIcon iconOff, iconOn, chipIcon, chipIcon_temp; private ImageIcon iconOff, iconOn, chipIcon, chipIcon_temp, iconOff_temp, iconOn_temp;
private JToggleButton but1, but2, but3; private JToggleButton but1, but2, but3;
private JLabel chiplabel, label1, label2, label3; private JLabel chiplabel, label1, label2, label3;
private int xscale = GUI.getxscale(); private int xscale = GUI.getxscale();
...@@ -36,21 +36,23 @@ public class Button extends Modul implements ActionListener { ...@@ -36,21 +36,23 @@ public class Button extends Modul implements ActionListener {
chipIcon = _icon; chipIcon = _icon;
iconOff = _icon1; iconOff = _icon1;
iconOn = _icon2; iconOn = _icon2;
iconOff_temp = iconOff;
iconOn_temp = iconOn;
chiplabel = new JLabel(); chiplabel = new JLabel();
but1 = new JToggleButton(); but1 = new JToggleButton();
but1.setIcon(iconOff); but1.setIcon(iconOff_temp);
but1.setActionCommand("0"); but1.setActionCommand("0");
but1.addActionListener(this); but1.addActionListener(this);
but2 = new JToggleButton(); but2 = new JToggleButton();
but2.setIcon(iconOff); but2.setIcon(iconOff_temp);
but2.setActionCommand("1"); but2.setActionCommand("1");
but2.addActionListener(this); but2.addActionListener(this);
but3 = new JToggleButton(); but3 = new JToggleButton();
but3.setIcon(iconOff); but3.setIcon(iconOff_temp);
but3.setActionCommand("2"); but3.setActionCommand("2");
but3.addActionListener(this); but3.addActionListener(this);
...@@ -79,13 +81,40 @@ public class Button extends Modul implements ActionListener { ...@@ -79,13 +81,40 @@ public class Button extends Modul implements ActionListener {
chipIcon_temp = new ImageIcon(chipIcon.getImage().getScaledInstance(((int)(0.3037*xscale)), ((int)(0.304*yscale)), Image.SCALE_SMOOTH)); chipIcon_temp = new ImageIcon(chipIcon.getImage().getScaledInstance(((int)(0.3037*xscale)), ((int)(0.304*yscale)), Image.SCALE_SMOOTH));
chiplabel.setIcon(chipIcon_temp); chiplabel.setIcon(chipIcon_temp);
chiplabel.setSize(((int)(0.3037*xscale)), ((int)(0.304*yscale))); chiplabel.setSize(((int)(0.3037*xscale)), ((int)(0.304*yscale)));
layerpane.add(chiplabel, 0);
but1.setSize(((int)(0.0723*xscale)), ((int)(0.0724*yscale))); but1.setSize(((int)(0.0723*xscale)), ((int)(0.0724*yscale)));
label1.setSize(((int)(0.0723*xscale)), ((int)(0.0724*yscale))); label1.setSize(((int)(0.0723*xscale)), ((int)(0.0724*yscale)));
label1.setLocation(((int)(0.02996*xscale)), ((int)(0.06618*yscale))); label1.setLocation(((int)(0.02996*xscale)), ((int)(0.06618*yscale)));
iconOff_temp = new ImageIcon(iconOff.getImage().getScaledInstance(((int)(0.0723*xscale)), ((int)(0.0724*yscale)), Image.SCALE_SMOOTH));
iconOn_temp = new ImageIcon(iconOn.getImage().getScaledInstance(((int)(0.0723*xscale)), ((int)(0.0724*yscale)), Image.SCALE_SMOOTH));
//Abfrage ob der jeweilige Button im moment gedrckt wurde oder nicht und dementsprechend wird das gas gezoomte icon gesetzt
if(!but1.isSelected())
but1.setIcon(iconOff_temp);
else
but1.setIcon(iconOn_temp);
if(!but2.isSelected())
but2.setIcon(iconOff_temp);
else
but2.setIcon(iconOn_temp);
if(!but3.isSelected())
but3.setIcon(iconOff_temp);
else
but3.setIcon(iconOn_temp);
but2.setSize(((int)(0.0723*xscale)), ((int)(0.0724*yscale))); but2.setSize(((int)(0.0723*xscale)), ((int)(0.0724*yscale)));
...@@ -100,6 +129,7 @@ public class Button extends Modul implements ActionListener { ...@@ -100,6 +129,7 @@ public class Button extends Modul implements ActionListener {
label1.add(but1); label1.add(but1);
label2.add(but2); label2.add(but2);
label3.add(but3); label3.add(but3);
layerpane.add(chiplabel, 0);
layerpane.add(label1, 0); layerpane.add(label1, 0);
layerpane.add(label2, 0); layerpane.add(label2, 0);
layerpane.add(label3, 0); layerpane.add(label3, 0);
...@@ -141,9 +171,9 @@ public class Button extends Modul implements ActionListener { ...@@ -141,9 +171,9 @@ public class Button extends Modul implements ActionListener {
Integer pin = Integer.parseInt(arg0.getActionCommand()); Integer pin = Integer.parseInt(arg0.getActionCommand());
boolean bool = ((JToggleButton) arg0.getSource()).isSelected(); boolean bool = ((JToggleButton) arg0.getSource()).isSelected();
if (bool) { if (bool) {
((JToggleButton) arg0.getSource()).setIcon(iconOn); ((JToggleButton) arg0.getSource()).setIcon(iconOn_temp);
} else { } else {
((JToggleButton) arg0.getSource()).setIcon(iconOff); ((JToggleButton) arg0.getSource()).setIcon(iconOff_temp);
} }
int value = 0; int value = 0;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment