java - Search same colors (RGB) in same position (i, j) from different arrays (3 array) and lock it -
i made simple learning program create 3 array, put jpanel
it, , give random color each (each array have own "randomizer" jtogglebutton
)
for learning continuation, thinking of creating 1 more button search same colors in same position arrays array1 [0][0] (r, g, b) = array2 [0][0] (r, g, b), , lock it (so loop can't revalidate color).
my questions are:
- is possible lock position of array array [0][9]?
- i think should make randomizing loops synchronize first, methodically right?
- if possible, should start build it?
- it not question but, please give me instigation if make unnecessary "// copy method" except jtogglebuttons.
p.s. question how check 2 array list same content in same position, maybe next step method, others in different language , don't think has same issue.
the code:
main:
public class main { private static void createmainframe() { new window().initmainframe(); } @suppresswarnings("convert2lambda") public static void main (string [] args) { swingutilities.invokelater (new runnable() { @override public void run() { createmainframe(); } }); } }
window:
public class window { public void initmainframe() { container container = mainframe.getcontentpane(); container.setlayout(null); } private static void createblocks1() { new blocks().initblocks1(); } // createblocks2 // createblocks3 public static jframe mainframe = new jframe("learning 43"); public static jpanel viewerboard1 = new jpanel(); // viewerboard2 // viewerboard3 public static jtogglebutton randomize1 = new jtogglebutton("randomizer"); // randomize2 // randomize3 @suppresswarnings("convert2lambda") public window() { initmainframe(); mainframe.setsize(676,357); mainframe.setlocationrelativeto(null); mainframe.setresizable(false); mainframe.setalwaysontop(true); mainframe.setdefaultcloseoperation(jframe.exit_on_close); mainframe.setvisible(true); mainframe.add(viewerboard1); viewerboard1.setbounds(15, 15, 200, 200); viewerboard1.setbackground(new color(222, 222, 222)); viewerboard1.setvisible(true); // viewerboard2 // viewerboard3 jpanel viewerpanel1 = new jpanel(); mainframe.add(viewerpanel1); viewerpanel1.setbounds(10, 10, 210, 210); viewerpanel1.setbackground(new color(111, 111, 111)); viewerpanel1.setborder(borderfactory.createbevelborder(bevelborder.lowered)); viewerpanel1.setvisible(true); // viewerpanel2 // viewerpanel3 mainframe.add(randomize1); randomize1.setfocuspainted(false); randomize1.setrolloverenabled(true); randomize1.setforeground(color.gray); randomize1.setfont(new font("courier", font.bold, 16)); randomize1.setmargin(new insets(0, 0, 0, 0)); randomize1.setbounds(10, 230, 210, 90); randomize1.setvisible(true); randomize1.additemlistener(new itemlistener() { @override public void itemstatechanged(itemevent randomevent) { if (randomevent.getstatechange() == itemevent.selected){ system.out.println("randomize button 1 selected: " + randomize1.isselected()); system.out.println("randomizing panel 1..."); while (randomize1.isselected()) { createblocks1(); break; } } if (randomevent.getstatechange() == itemevent.deselected){ system.out.println("randomize button 1 deselcted!"); system.out.println("eraseing panel 1..."); viewerboard1.removeall(); viewerboard1.revalidate(); viewerboard1.repaint(); } } }); // randomize2 // randomize3 } }
blocks:
public class blocks { public void initblocks1() { blockthread1 thread1 = new blockthread1(); thread1.start(); } // initblocks2 // initblocks3 container container = window.viewerboard1; jpanel [][] blocksarray1 = new jpanel[4][4]; jpanel colspanel; jpanel rowspanel; random random1 = new random(); private color rcolor1() { return new color(random1.nextint(255), random1.nextint(255), random1.nextint(255)/*, random.nextint(255)*/); } class blockthread1 extends thread { @override public void run(){ container.setlayout(new gridlayout(4, 4)); { try { (int cols1 = 0; cols1 < blocksarray1.length; cols1++) { colspanel = new jpanel(); colspanel.setbackground(rcolor1()); window.viewerboard1.revalidate(); window.viewerboard1.add(colspanel); (int rows1 = 1; rows1 < blocksarray1[cols1].length; rows1++) { rowspanel = new jpanel(); rowspanel.setbackground(rcolor1()); window.viewerboard1.revalidate(); window.viewerboard1.add(rowspanel); } } thread.sleep(1000); window.viewerboard1.removeall(); window.viewerboard1.revalidate(); window.viewerboard1.repaint(); } catch (interruptedexception ex) { java.util.logging.logger.getlogger(window.class.getname()).log(java.util.logging.level.severe, null, ex); } } while (window.randomize1.isselected()); } } // blocksarray2 // blocksarray3 }
Comments
Post a Comment