Simple single-color 8x8x8 LED Cube with AVRs
Ви не можете вибрати більше 25 тем Теми мають розпочинатися з літери або цифри, можуть містити дефіси (-) і не повинні перевищувати 35 символів.

layerEditFrame.java 3.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
  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. ImageIcon on = new ImageIcon(getClass().getResource("LEDon.png"));
  17. ImageIcon off = new ImageIcon(getClass().getResource("LEDoff.png"));
  18. boolean changedStateSinceSave = false;
  19. byte[] frame;
  20. // Ende Attribute
  21. public layerEditFrame(byte[] f) {
  22. // Frame-Initialisierung
  23. super("Layer Edit");
  24. frame = f;
  25. setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
  26. int frameWidth = 180;
  27. int frameHeight = 230;
  28. setSize(frameWidth, frameHeight);
  29. Dimension d = Toolkit.getDefaultToolkit().getScreenSize();
  30. int x = (d.width - getSize().width) / 2;
  31. int y = (d.height - getSize().height) / 2;
  32. setLocation(x, y);
  33. setResizable(false);
  34. Container cp = getContentPane();
  35. cp.setLayout(null);
  36. for(int i = 0; i < 8; i++){
  37. for(int j = 0; j < 8; j++){
  38. final int finalI = i;
  39. final int finalJ = j;
  40. ledPanels[i][j] = new JButton(on);
  41. ledPanels[i][j].setBounds((i*20)+5, (j*20)+5, 15, 15);
  42. ledPanels[i][j].addActionListener(new ActionListener() {
  43. public void actionPerformed(ActionEvent evt) {
  44. btnClicked(finalI, finalJ);
  45. }
  46. });
  47. ledPanels[i][j].setVisible(true);
  48. cp.add(ledPanels[i][j]);
  49. }
  50. }
  51. loadData();
  52. JButton saveBtn = new JButton("Save");
  53. JButton cancelBtn = new JButton("Cancel");
  54. saveBtn.setBounds(5, 170, 70, 25);
  55. saveBtn.setFont(new Font("Dialog", Font.PLAIN, 13));
  56. cp.add(saveBtn);
  57. cancelBtn.setBounds(80, 170, 80, 25);
  58. cancelBtn.setFont(new Font("Dialog", Font.PLAIN, 13));
  59. cp.add(cancelBtn);
  60. setVisible(true);
  61. saveBtn.addActionListener(new ActionListener() {
  62. public void actionPerformed(ActionEvent evt) {
  63. save();
  64. }
  65. });
  66. cancelBtn.addActionListener(new ActionListener() {
  67. public void actionPerformed(ActionEvent evt) {
  68. cancel();
  69. }
  70. });
  71. addWindowListener(new WindowAdapter() {
  72. public void windowClosing(WindowEvent evt) {
  73. if(changedStateSinceSave){
  74. saveExitDialog();
  75. }
  76. dispose();
  77. }
  78. });
  79. }
  80. // Anfang Komponenten
  81. // Ende Komponenten
  82. private void loadData(){
  83. byte[][] frameArray = new byte[8][8];
  84. //Load the data from the bytearray 'frame' and write it into frameArray.length A 0 means off, everything else means on
  85. for(int i = 0; i < frameArray.length; i++){ //
  86. for(int j = 0; j < frameArray[i].length; j++){ //This ist just that we have a starting point....
  87. frameArray[i][j] = 0; //
  88. }
  89. }
  90. for(int i = 0; i < frameArray.length; i++){ //
  91. for(int j = 0; j < frameArray[i].length; j++){ //Set the LED-Buttons
  92. if(frameArray[i][j] == 0){
  93. ledPanels[i][j].setIcon(off);
  94. } else {
  95. ledPanels[i][j].setIcon(on);
  96. }
  97. }
  98. }
  99. }
  100. public void btnClicked(int i, int j){
  101. changedStateSinceSave = true;
  102. if (ledPanels[i][j].getIcon() == on){
  103. ledPanels[i][j].setIcon(off);
  104. } else {
  105. ledPanels[i][j].setIcon(on);
  106. }
  107. }
  108. public void cancel(){
  109. dispose();
  110. }
  111. public void save(){
  112. changedStateSinceSave = false;
  113. }
  114. private int saveExitDialog() {
  115. String[] Optionen = {"Yes", "No"};
  116. int Auswahl = JOptionPane.showOptionDialog(this, "Do you want to save your changes?", "Save?", JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE, null, Optionen, Optionen[0]);
  117. if (Auswahl == JOptionPane.YES_OPTION) {
  118. save();
  119. return 1;
  120. } else {
  121. return 0;
  122. }
  123. }
  124. }