Simple single-color 8x8x8 LED Cube with AVRs
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

layerEditFrame.java 2.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  1. import java.awt.*;
  2. import java.awt.event.*;
  3. import javax.swing.*;
  4. import javax.swing.event.*;
  5. /**
  6. *
  7. * Beschreibung
  8. *
  9. * @version 1.0 vom 11/16/2011
  10. * @author
  11. */
  12. public class layerEditFrame extends JFrame {
  13. // Anfang Attribute
  14. private JPanel panelLED1 = new JPanel(null, true);
  15. JButton[][] ledPanels = new JButton[8][8];
  16. static ImageIcon on = new ImageIcon("LEDon.png");
  17. static ImageIcon off = new ImageIcon("LEDoff.png");
  18. // Ende Attribute
  19. public layerEditFrame() {
  20. // Frame-Initialisierung
  21. super("Layer Edit");
  22. setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
  23. int frameWidth = 180;
  24. int frameHeight = 230;
  25. setSize(frameWidth, frameHeight);
  26. Dimension d = Toolkit.getDefaultToolkit().getScreenSize();
  27. int x = (d.width - getSize().width) / 2;
  28. int y = (d.height - getSize().height) / 2;
  29. setLocation(x, y);
  30. setResizable(false);
  31. Container cp = getContentPane();
  32. cp.setLayout(null);
  33. for(int i = 0; i < 8; i++){
  34. for(int j = 0; j < 8; j++){
  35. final int finalI = i;
  36. final int finalJ = j;
  37. ledPanels[i][j] = new JButton(on);
  38. ledPanels[i][j].setBounds((i*20)+5, (j*20)+5, 15, 15);
  39. ledPanels[i][j].addActionListener(new ActionListener() {
  40. public void actionPerformed(ActionEvent evt) {
  41. btnClicked(finalI, finalJ);
  42. }
  43. });
  44. ledPanels[i][j].setVisible(true);
  45. cp.add(ledPanels[i][j]);
  46. }
  47. }
  48. JButton saveBtn = new JButton("Save");
  49. JButton cancelBtn = new JButton("Cancel");
  50. saveBtn.setBounds(5, 170, 70, 25);
  51. saveBtn.setFont(new Font("Dialog", Font.PLAIN, 13));
  52. cp.add(saveBtn);
  53. cancelBtn.setBounds(80, 170, 80, 25);
  54. cancelBtn.setFont(new Font("Dialog", Font.PLAIN, 13));
  55. cp.add(cancelBtn);
  56. setVisible(true);
  57. saveBtn.addActionListener(new ActionListener() {
  58. public void actionPerformed(ActionEvent evt) {
  59. save();
  60. }
  61. });
  62. cancelBtn.addActionListener(new ActionListener() {
  63. public void actionPerformed(ActionEvent evt) {
  64. cancel();
  65. }
  66. });
  67. addWindowListener(new WindowAdapter() {
  68. public void windowClosing(WindowEvent evt) {
  69. saveExitDialog();
  70. dispose();
  71. }
  72. });
  73. }
  74. // Anfang Komponenten
  75. // Ende Komponenten
  76. public void btnClicked(int i, int j){
  77. if (ledPanels[i][j].getIcon() == on){
  78. ledPanels[i][j].setIcon(off);
  79. } else {
  80. ledPanels[i][j].setIcon(on);
  81. }
  82. }
  83. public void cancel(){
  84. dispose();
  85. }
  86. public void save(){
  87. }
  88. private int saveExitDialog() {
  89. String[] Optionen = {"Yes", "No"};
  90. int Auswahl = JOptionPane.showOptionDialog(this, "Do you want to save your changes?", "Save?", JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE, null, Optionen, Optionen[0]);
  91. if (Auswahl == JOptionPane.YES_OPTION) {
  92. save();
  93. return 1;
  94. } else {
  95. return 0;
  96. }
  97. }
  98. }