Advertisement
Guest User

Jeronimus

a guest
May 5th, 2016
203
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 20.62 KB | None | 0 0
  1. import java.util.Random;
  2. import java.math.BigInteger;
  3. import java.util.ArrayList;
  4. import java.util.Arrays;
  5. import java.awt.AlphaComposite;
  6.  
  7. import java.awt.Graphics;
  8. import java.awt.Rectangle;
  9. import java.awt.*;
  10. import javax.swing.*;
  11. import java.awt.event.*;
  12.  
  13.  
  14. class cliquesGame3 {
  15.  
  16.  
  17. public static void main(String[] args) {
  18.  
  19.  
  20. System.setProperty("java.util.Arrays.useLegacyMergeSort", "true");
  21. int border = 40;
  22. int squareSize = 665;
  23. int numberOfStudents = 17;
  24. int minConnections = 6;
  25. int maxConnections = 9;
  26. long seed = new Random().nextLong();
  27. new mainBody(minConnections, maxConnections, numberOfStudents, seed, squareSize, border);
  28. }
  29. }
  30.  
  31.  
  32. class mainBody extends JFrame implements ActionListener {
  33.  
  34.  
  35. int numberOfStudents, minConnections,maxConnections,squareSize,
  36. border,restartMinConnections,restartMaxConnections,restartNumberOfStudents,restartSquareSize;
  37.  
  38. long seed;
  39. boolean lock= true;
  40. double tileSize;
  41. Color setColor = Color.red;
  42. Color unsetColor = new Color(144,144,144);
  43.  
  44.  
  45. Random rnd;
  46.  
  47. Rectangle rectangleA = new Rectangle();
  48. Rectangle rectangleB = new Rectangle();
  49.  
  50. ArrayList<Integer> toBeSwitchedX = new ArrayList<Integer>();
  51. ArrayList<Integer> toBeSwitchedY = new ArrayList<Integer>();
  52. Student[] arrayOfStudents;
  53.  
  54. JPanel jPanel;
  55. JTextField textField, minTextField, maxTextField, studentsTextField, squareSizeTextField;
  56. JustButton[] jbX;
  57. JustButton[] jbY;
  58. MyButton[][] myButton;
  59. JCheckBox checkBox;
  60.  
  61. public void restart() {
  62.  
  63. ensureConsistency();
  64. minConnections=Integer.parseInt(minTextField.getText());
  65. maxConnections=Integer.parseInt(maxTextField.getText());
  66. numberOfStudents=Integer.parseInt(studentsTextField.getText());
  67. squareSize=Integer.parseInt(squareSizeTextField.getText());
  68. if (squareSize<550){
  69. squareSize=550;
  70. squareSizeTextField.setText("550");
  71. }
  72.  
  73. this.dispose();
  74. new mainBody(minConnections, maxConnections,numberOfStudents,seed,squareSize,border);
  75. }
  76.  
  77. public mainBody(int minConnections, int maxConnections, int numberOfStudents, long seed, int squareSize,int border) {
  78.  
  79. this.minConnections = minConnections;
  80. this.maxConnections = maxConnections;
  81. this.numberOfStudents = numberOfStudents;
  82. this.seed = seed;
  83. this.squareSize = squareSize;
  84. this.border = border;
  85.  
  86. restartMinConnections= minConnections;
  87. restartMaxConnections= maxConnections;
  88. restartNumberOfStudents= numberOfStudents;
  89. restartSquareSize= squareSize;
  90.  
  91. tileSize = (double)squareSize/(double)(numberOfStudents+1);
  92. rnd = new Random(seed);
  93.  
  94. createStudents(numberOfStudents);
  95. randomlyInterconnectStudents(minConnections, maxConnections);
  96. giveEachStudentColors();
  97. setupWindow();
  98. plotGraphicalRepresentation();
  99.  
  100. }
  101.  
  102. public void createStudents(int numberOfStudents) {
  103. arrayOfStudents = new Student[numberOfStudents];
  104. for (int i=0; i<numberOfStudents; i++) {
  105. arrayOfStudents[i] = new Student();
  106. }
  107. }
  108.  
  109. public void randomlyInterconnectStudents(int minConnections, int maxConnections){
  110. for (int i=0; i< numberOfStudents; i++) {
  111. int numberOfConnections = rnd.nextInt(maxConnections - (minConnections-1)) + minConnections;
  112. arrayOfStudents[i].arrayOfConnectedStudents = new int[numberOfConnections];
  113. }
  114. int flag;
  115. int studentToBeAdded;
  116. int studentsContained;
  117. for (int i=0; i<numberOfStudents; i++) {
  118. studentsContained = arrayOfStudents[i].arrayOfConnectedStudents.length;
  119. arrayOfStudents[i].arrayOfConnectedStudents = new int[studentsContained];
  120. for(int x=0; x<studentsContained; x++) {
  121. // lazy way of making sure no same students are contained in the array
  122. do {
  123. studentToBeAdded= rnd.nextInt(numberOfStudents)+1;
  124. flag = 0;
  125. for(int o=0; o<studentsContained; o++) {
  126. if (arrayOfStudents[i].arrayOfConnectedStudents[o] == studentToBeAdded) {flag = 1;}
  127. }
  128. }
  129. while (flag ==1);
  130. arrayOfStudents[i].arrayOfConnectedStudents[x]=studentToBeAdded;
  131. arrayOfStudents[studentToBeAdded-1].arrayListFromConnections.add(i+1);
  132. }
  133. }
  134. }
  135.  
  136. public void giveEachStudentColors() {
  137. for (int i=0; i<numberOfStudents; i++) {
  138. int studentsContained = arrayOfStudents[i].arrayOfConnectedStudents.length;
  139. int studentsFromConnections = arrayOfStudents[i].arrayListFromConnections.size();
  140. arrayOfStudents[i].colorOfStudent = BigInteger.valueOf(1).shiftLeft(i);
  141. for (int x=0; x<studentsContained; x++) {
  142. arrayOfStudents[i].colorOfStudent = arrayOfStudents[i].colorOfStudent.or(BigInteger.valueOf(1).shiftLeft(arrayOfStudents[i].arrayOfConnectedStudents[x]-1));
  143. }
  144. for (int x=0; x<studentsFromConnections; x++) {
  145. arrayOfStudents[i].colorOfStudent = arrayOfStudents[i].colorOfStudent.or(BigInteger.valueOf(1).shiftLeft(arrayOfStudents[i].arrayListFromConnections.get(x)-1));
  146. }
  147. // System.out.println(String.format("%"+Integer.toString(numberOfStudents)+"s", arrayOfStudents[i].colorOfStudent.toString(2)).replace(' ', '0'));
  148. String str = String.format("%"+Integer.toString(numberOfStudents)+"s", arrayOfStudents[i].colorOfStudent.toString(2)).replace(' ', '0');
  149. arrayOfStudents[i].colorString = str;
  150. arrayOfStudents[i].arrayColorOfStudent = new int[numberOfStudents];
  151. for (int x=0; x<numberOfStudents; x++) {
  152. arrayOfStudents[i].arrayColorOfStudent[x] = Character.getNumericValue(str.charAt(numberOfStudents-x-1));
  153. }
  154. }
  155. }
  156.  
  157. public void setupWindow() {
  158. this.setName("cliqueGame");
  159. jPanel = new JPanel();
  160.  
  161. jPanel.setLayout(null);
  162. jPanel.setBackground(Color.black);
  163.  
  164. checkBox = new JCheckBox("interlock Columns/Rows",true);
  165. checkBox.addActionListener(this);
  166. checkBox.setActionCommand("lock");
  167. checkBox.setBounds(0,(int)(squareSize+2),170,border);
  168. jPanel.add(checkBox);
  169.  
  170. minTextField = new JTextField(Integer.toString(restartMinConnections));
  171. maxTextField = new JTextField(Integer.toString(restartMaxConnections));
  172. studentsTextField = new JTextField(Integer.toString(restartNumberOfStudents));
  173. squareSizeTextField = new JTextField(Integer.toString(restartSquareSize));
  174.  
  175. minTextField.setActionCommand("miT");
  176. maxTextField.setActionCommand("maT");
  177. studentsTextField.setActionCommand("studentsT");
  178. squareSizeTextField.setActionCommand("squareT");
  179.  
  180. minTextField.addActionListener(this);
  181. maxTextField.addActionListener(this);
  182. studentsTextField.addActionListener(this);
  183. squareSizeTextField.addActionListener(this);
  184.  
  185. minTextField.setBounds((int)450+2,(int)(squareSize+2),(squareSize-450)/4,border);
  186. maxTextField.setBounds((int)450+((squareSize-450)/4)*1+2,(int)(squareSize+2),(squareSize-450)/4,border);
  187. studentsTextField.setBounds((int)450+((squareSize-450)/4)*2+2,(int)(squareSize+2),(squareSize-450)/4,border);
  188. squareSizeTextField.setBounds((int)450+((squareSize-450)/4)*3+2,(int)(squareSize+2),(squareSize-450)/4,border);
  189.  
  190. MyButton printMatrix = new MyButton(Color.green,Color.green,tileSize);
  191. printMatrix.setBounds((int)(tileSize*numberOfStudents)+1,0,(int)tileSize-3,(int)tileSize-3);
  192. printMatrix.addActionListener(this);
  193. printMatrix.setActionCommand("print");
  194.  
  195. jPanel.add(printMatrix);
  196.  
  197. jPanel.add(minTextField);
  198. jPanel.add(maxTextField);
  199. jPanel.add(studentsTextField);
  200. jPanel.add(squareSizeTextField);
  201.  
  202. textField = new JTextField("enter seed here+enter: "+Long.toString(seed));
  203. textField.setActionCommand("enter");
  204. textField. setBounds(172,(int)(squareSize+2),450-172,border);;
  205.  
  206. textField.addActionListener(this);
  207. jPanel.add(textField);
  208.  
  209. this.add(jPanel);
  210.  
  211. MyGlassPane glassPane = new MyGlassPane();
  212.  
  213. this.setGlassPane(glassPane);
  214. glassPane.setVisible(true);
  215.  
  216. this.setResizable(false);
  217. this.setSize((int)((tileSize)*(numberOfStudents+1)+5),(int)(tileSize*(numberOfStudents+1)+border+20));
  218. this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  219. this.setVisible(true);// try {Thread.sleep(1000);}catch (Exception e){}
  220. }
  221.  
  222. public void plotGraphicalRepresentation(){
  223. jbX = new JustButton[numberOfStudents];
  224. jbY = new JustButton[numberOfStudents];
  225. myButton = new MyButton[numberOfStudents][numberOfStudents];
  226.  
  227. for(int i=0; i<numberOfStudents;i++) {
  228. jbX[numberOfStudents-i-1] = new JustButton(Integer.toString(numberOfStudents-i-1));
  229. jbY[i]= new JustButton(Integer.toString(i));
  230. jbX[numberOfStudents-i-1].setBorder(null);
  231. jbY[i].setBorder(null);
  232. jbX[numberOfStudents-i-1].setFont(new Font("Arial", Font.PLAIN, (int)(tileSize-tileSize/5)));
  233. jbY[i].setFont(new Font("Arial", Font.PLAIN, (int)(tileSize-tileSize/5)));
  234. jbX[numberOfStudents-i-1].setBounds((int)(i*tileSize),0,(int)tileSize-1,(int)tileSize-1);
  235. jbY[i].setBounds((int)(tileSize*numberOfStudents),(int)(tileSize+i*tileSize),(int)tileSize-1,(int)tileSize-1);
  236. jPanel.add(jbX[numberOfStudents-i-1]);
  237. jPanel.add(jbY[i]);
  238. jbX[numberOfStudents-i-1].addActionListener(this);
  239. jbX[numberOfStudents-i-1].setActionCommand(Integer.toString(numberOfStudents-i-1)+"x");
  240. jbY[i].addActionListener(this);
  241. jbY[i].setActionCommand(Integer.toString(i)+"y");
  242. }
  243.  
  244. for (int i=0; i<numberOfStudents; i++) {
  245. for (int x=0; x<numberOfStudents; x++) {
  246. if (arrayOfStudents[i].colorString.charAt(x) == '1') {
  247. myButton[numberOfStudents-x-1][i] = new MyButton(setColor,setColor,tileSize);
  248. jPanel.add(myButton[numberOfStudents-x-1][i]);
  249. myButton[numberOfStudents-x-1][i].setBounds((int)(x*tileSize+1),(int)(tileSize+i*tileSize+1),(int)tileSize-3,(int)tileSize-3);
  250. myButton[numberOfStudents-x-1][i].addActionListener(this);
  251. myButton[numberOfStudents-x-1][i].setActionCommand("myButton");
  252. myButton[numberOfStudents-x-1][i].bit = 1;
  253. myButton[numberOfStudents-x-1][i].posX=numberOfStudents-x-1;
  254. myButton[numberOfStudents-x-1][i].posY=i;
  255.  
  256. } else {
  257. myButton[numberOfStudents-x-1][i] = new MyButton(unsetColor, unsetColor,tileSize);
  258. jPanel.add( myButton[numberOfStudents-x-1][i]);
  259. myButton[numberOfStudents-x-1][i].setBounds((int)(x*tileSize+1),(int)(tileSize+i*tileSize+1),(int)tileSize-3,(int)tileSize-3);
  260. myButton[numberOfStudents-x-1][i].addActionListener(this);
  261. myButton[numberOfStudents-x-1][i].setActionCommand("myButton");
  262. myButton[numberOfStudents-x-1][i].posX=numberOfStudents-x-1;
  263. myButton[numberOfStudents-x-1][i].posY=i;
  264.  
  265. }
  266. }
  267. }
  268.  
  269. jPanel.repaint();
  270. repaint();
  271. }
  272.  
  273. public void ensureConsistency() {
  274. restartNumberOfStudents = Integer.parseInt(studentsTextField.getText());
  275. restartMaxConnections = Integer.parseInt(maxTextField.getText());
  276. restartMinConnections = Integer.parseInt(minTextField.getText());
  277.  
  278. if (restartMaxConnections > restartNumberOfStudents) {
  279. restartMaxConnections = restartNumberOfStudents;
  280. maxTextField.setText(Integer.toString(restartMaxConnections));
  281. }
  282.  
  283. if (restartMinConnections > restartMaxConnections) {
  284. restartMinConnections = restartMaxConnections;
  285. minTextField.setText(Integer.toString(restartMaxConnections));
  286. }
  287. }
  288.  
  289. MyButton highButton;
  290. int counter = 0;
  291. int highlightX = 0;
  292. int highlightY = 0;
  293.  
  294. public void actionPerformed(ActionEvent e) {
  295.  
  296. String str=e.getActionCommand();
  297.  
  298.  
  299. if (str=="myButton"){
  300.  
  301. MyButton tempButton = (MyButton)e.getSource();
  302.  
  303. int x = tempButton.posX;
  304. int y = tempButton.posY;
  305.  
  306. if (tempButton.highlight == 0 && counter == 0) {
  307. System.out.println(counter+" "+tempButton.highlight);
  308. highButton = tempButton;
  309. tempButton.switchHighlight();
  310. highlightX = x;
  311. highlightY = y;
  312. counter++;
  313.  
  314. } else if (tempButton.highlight == 1 && counter == 1) {
  315. System.out.println(counter+" "+tempButton.highlight);
  316. System.out.println(tempButton.color);
  317. tempButton.switchHighlight();
  318. counter--;
  319.  
  320.  
  321. } else if (tempButton.highlight == 0 && counter ==1) {
  322.  
  323. counter--;
  324. highButton.switchHighlight();
  325.  
  326. if (highlightX < x ^ highlightX > x) {
  327. if (lock==true) {
  328. switchColumns(highlightX,x);
  329. switchRows(highlightX,x);
  330. } else {
  331. switchColumns(highlightX,x);
  332. }
  333. }
  334. if (highlightY < y ^ highlightY > y) {
  335.  
  336. if (lock==true) {
  337. switchColumns(highlightY,y);
  338. switchRows(highlightY,y);
  339. } else {
  340. switchRows(highlightY,y);
  341. }
  342. }
  343. }
  344. return;
  345. }
  346.  
  347.  
  348. if (str=="print"){
  349. for (int y=0; y< numberOfStudents;y++){
  350. System.out.println();
  351. for (int x=0; x< numberOfStudents;x++){
  352.  
  353. System.out.print(myButton[x][y].bit);
  354. }
  355. }
  356. return;
  357. }
  358.  
  359. if (str=="miT"){
  360. String s = minTextField.getText().replaceAll("[^\\d]", "");
  361. minTextField.setText(s);
  362. restartMinConnections = Integer.parseInt(s);
  363. ensureConsistency();
  364. return;
  365. }
  366.  
  367. if (str=="maT"){
  368. String s = maxTextField.getText().replaceAll("[^\\d]", "");
  369. maxTextField.setText(s);
  370. restartMaxConnections = Integer.parseInt(s);
  371. ensureConsistency();
  372. return;
  373. }
  374.  
  375. if (str=="studentsT"){
  376. String s = studentsTextField.getText().replaceAll("[^\\d]", "");
  377. studentsTextField.setText(s);
  378. restartNumberOfStudents = Integer.parseInt(s);
  379. ensureConsistency();
  380. return;
  381. }
  382.  
  383. if (str=="squareT"){
  384. String s = squareSizeTextField.getText().replaceAll("[^\\d]", "");
  385. squareSizeTextField.setText(s);
  386. restartSquareSize = Integer.parseInt(s);
  387. ensureConsistency();
  388. return;
  389. }
  390.  
  391.  
  392. if(str=="lock") {
  393. if (lock==true){
  394. lock = false;
  395. return;
  396. } else {
  397. lock = true; }
  398. return;
  399. }
  400.  
  401. if (str=="enter"){
  402. String s = textField.getText().replaceAll("[^\\d-]", "");
  403. int sl = s.length();
  404. if (s.length() == 0){seed = rnd.nextLong();restart();return;}
  405.  
  406. if (s.charAt(0)=='-' && sl < 2) {seed = rnd.nextLong();restart();return;}
  407.  
  408. s = s.substring(0,1)+s.substring(1,sl).replace("-", "");
  409. sl = s.length();
  410. BigInteger ba = new BigInteger(s);
  411. BigInteger bb = new BigInteger(Long.toString((long)Math.pow(2,63)));
  412. BigInteger bc = new BigInteger(Long.toString(-(long)Math.pow(2,63)-1));
  413. if ((ba.compareTo(bb))==1) {
  414. textField.setText(Long.toString((long)Math.pow(2,63)));
  415. } else if (ba.compareTo(bc) ==-1) {
  416. System.out.println("i was here");
  417. textField.setText(Long.toString(-(long)(Math.pow(2,63))));
  418. return;
  419. } else {
  420. if (sl >= 20 && (s.charAt(0) != '-')) {
  421. sl = 19;
  422. } else if (sl >= 20 && (s.charAt(0) == '-')){
  423. sl = 20;
  424. }
  425. seed = Long.parseLong(s.substring(0,sl));
  426. textField.setText(Long.toString(seed));
  427. restart();
  428. }
  429. }
  430.  
  431. int m,n;
  432.  
  433. if(str.contains("x")){
  434. int a = Integer.parseInt(str.substring(0,str.length()-1));
  435. if (toBeSwitchedX.contains(a)){
  436. toBeSwitchedX.remove((Integer)a);
  437. jbX[a].unsetBackground();
  438. return;
  439. } else {
  440. toBeSwitchedX.add(a);
  441. jbX[a].setBackground();
  442. if(toBeSwitchedX.size()==2) {
  443. jbX[toBeSwitchedX.get(0)].unsetBackground();
  444. jbX[toBeSwitchedX.get(1)].unsetBackground();
  445. n = toBeSwitchedX.get(0);
  446. m =toBeSwitchedX.get(1);
  447. if (lock == true) {
  448. switchColumns(m,n);
  449. switchRows(m,n);
  450. } else {
  451. switchColumns(m,n);
  452. }
  453.  
  454. }
  455. }
  456. return;
  457. }
  458.  
  459. if(str.contains("y")){
  460. int a = Integer.parseInt(str.substring(0,str.length()-1));
  461. if (toBeSwitchedY.contains(a)){
  462. toBeSwitchedY.remove((Integer)a);
  463. jbY[a].unsetBackground();
  464. return;
  465. } else {
  466. toBeSwitchedY.add(a);
  467. jbY[a].setBackground();
  468. if(toBeSwitchedY.size()==2) {
  469. jbY[toBeSwitchedY.get(0)].unsetBackground();
  470. jbY[toBeSwitchedY.get(1)].unsetBackground();
  471. m = toBeSwitchedY.get(0);
  472. n =toBeSwitchedY.get(1);
  473. if (lock == true) {
  474.  
  475. switchColumns(m,n);
  476. switchRows(m,n);
  477. } else {
  478. switchRows(m,n);
  479. }
  480.  
  481. }
  482. }
  483. return;
  484. }
  485. }
  486.  
  487. public void switchColumns(int a, int b){
  488. for(int i=0; i<numberOfStudents; i++) {
  489. rectangleB = myButton[b][i].getBounds();
  490. rectangleA = myButton[a][i].getBounds();
  491. myButton[a][i].setBounds(rectangleB);
  492. myButton[b][i].setBounds(rectangleA);
  493. }
  494. toBeSwitchedX.clear();
  495. rectangleB = jbX[b].getBounds();
  496. rectangleA = jbX[a].getBounds();
  497. jbX[a].setBounds(rectangleB);
  498. jbX[b].setBounds(rectangleA);
  499. }
  500.  
  501. public void switchRows(int a, int b) {
  502. for(int i=0; i<numberOfStudents; i++) {
  503. rectangleB = myButton[i][b].getBounds();
  504. rectangleA = myButton[i][a].getBounds();
  505. myButton[i][a].setBounds(rectangleB);
  506. myButton[i][b].setBounds(rectangleA);
  507. }
  508. toBeSwitchedY.clear();
  509. rectangleB = jbY[b].getBounds();
  510. rectangleA = jbY[a].getBounds();
  511. jbY[a].setBounds(rectangleB);
  512. jbY[b].setBounds(rectangleA);
  513. }
  514.  
  515.  
  516. class MyGlassPane extends JComponent{
  517. AlphaComposite composite;
  518. Graphics2D g2d;
  519. float alpha;
  520. int type;
  521. int i=1;
  522. int o;
  523.  
  524. BasicStroke stroke;
  525.  
  526. MyGlassPane() {
  527. setVisible(true);
  528. stroke = new BasicStroke(3);
  529. }
  530.  
  531. public void paintComponent(Graphics g){
  532. g2d = (Graphics2D) g.create();
  533. alpha = 0.6f;
  534. type = AlphaComposite.SRC_OVER;
  535. composite = AlphaComposite.getInstance(type, alpha);
  536. g2d.setComposite(composite);
  537. g2d.setStroke(stroke);
  538. g2d.setColor(Color.black);
  539. g2d.drawLine((int)(squareSize-3-tileSize),(int)tileSize,0,(int)(squareSize-3));;
  540. if (i == 1) {
  541. o = counter;
  542. i = 0;
  543. }
  544. if (o!=counter) {
  545. i=1;
  546. this.repaint();
  547. }
  548. if (counter == 1) {
  549. g2d.setColor(Color.white);
  550. g2d.fillRect(highButton.getX(), 0,(int)tileSize,(int)(highButton.getY()));
  551. g2d.fillRect((int)(highButton.getX()+tileSize),(int)(highButton.getY()),(int)(squareSize-tileSize),(int)tileSize);
  552. }
  553. }
  554. }
  555. }
  556.  
  557.  
  558. class Student {
  559.  
  560.  
  561. BigInteger colorOfStudent;
  562. int[] arrayColorOfStudent;
  563. int[] arrayOfConnectedStudents;
  564. ArrayList<Integer> arrayListFromConnections = new ArrayList<Integer>();
  565. String colorString;
  566. }
  567.  
  568.  
  569. class MyButton extends JButton {
  570.  
  571.  
  572. double tileSize;
  573. Color backColor;
  574. Color color;
  575. String string;
  576. int bit;
  577. int posX;
  578. int posY;
  579. int highlight;
  580.  
  581. MyButton(String str) {
  582. str = string;
  583. setText(str);
  584. }
  585.  
  586. public MyButton(Color c, Color b,double size) {
  587. setBorder(null);
  588. setBackground(b);
  589. color = b;
  590. tileSize = size;
  591. }
  592.  
  593.  
  594. public void switchHighlight() {
  595.  
  596. if (highlight == 0) {
  597. highlight = 1;
  598. if (bit==1){
  599. setColor(Color.magenta);
  600. }else {
  601. setColor(Color.cyan);
  602. }
  603. } else {
  604. highlight = 0;
  605. if (bit == 1) {
  606. setColor(Color.red);}
  607. else {
  608. setColor(new Color(144,144,144));
  609. }
  610. }
  611. }
  612.  
  613. public void setColor(Color c){
  614. color = c;
  615. setBackground(c);
  616. setForeground(Color.white);
  617. }
  618.  
  619. public Color getColor(){
  620. return color;
  621. }
  622. }
  623.  
  624.  
  625. class JustButton extends JButton {
  626.  
  627.  
  628. double tileSize;
  629. Color backColor;
  630. Color color = Color.red;
  631. String string;
  632. Color col = new Color(188,188,188);
  633.  
  634. public JustButton(String str) {
  635. setBorder(null);
  636. setBackground(col);
  637. string = str;
  638. setText(string);
  639. }
  640.  
  641. public void setBackground() {
  642. setBackground(Color.red);
  643. }
  644.  
  645. public void unsetBackground() {
  646. setBackground(col);
  647. }
  648. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement