Simple single-color 8x8x8 LED Cube with AVRs
Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

layerEditFrame.java 3.1KB

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