java - Communicating between two JFrames -
sorry if question has been asked i'm having trouble understanding existing answers , need see related code. (i'm new java)
also sorry if similar code posted - tried doing 2 panels on 1 frame , couldnt working im trying method.
when button blacktrail pressed on frame2, changes color of projectile on frame1 black.
here's code far:
gui form class ( menu buttons etc)
public class guiform1 extends jframe{ //initialise components private jpanel mainpanel; private jpanel menupanel; private jbutton whitetrail; private jbutton blacktrail; private jbutton redtrail; private jbutton bluetrail; private jbutton greentrail; private jbutton purpletrail; //irrelevant components public guiform1() { jframe frame2 = new jframe("projectile motion - menu"); frame2.setcontentpane(mainpanel); frame2.setdefaultcloseoperation(windowconstants.hide_on_close); frame2.pack(); frame2.setvisible(true); } }
physics sim class (main , graphics drawing)
public class physicssim extends jcomponent { public static void main(string[] args) { //building frame fit correct screen size jframe frame1 = new jframe("projectile motion - animation"); physicssim sim = new physicssim(); frame1.add(sim); frame1.setdefaultcloseoperation(windowconstants.exit_on_close); frame1.setlocationrelativeto(null); frame1.setvisible(true); frame1.setextendedstate(frame1.maximized_both); guiform1 guiform1 = new guiform1(); } public void paintcomponent(graphics g) { //background g.setcolor(new color(149, 179, 215)); g.fillrect(0, 0, getwidth(), getheight()); super.paintcomponent(g); //axis g.setcolor(color.black); g.fillrect(50, 0, 5, getheight()); g.fillrect(0, getheight() - 50, getwidth(), 5); int axisy = 0; int axisx = 0; int axisycounter = 1; int axisxcounter = 1; //axis markers while (axisycounter <= getheight() / 10) { g.fillrect(35, axisy, 20, 5); axisy = axisy + 50; axisycounter++; } while (axisxcounter <= getwidth() / 10) { g.fillrect(axisx, getheight() - 50, 5, 20); axisx = axisx + 50; axisxcounter++; } //projectile g.setcolor(c); g.filloval(getwidth() - 1885, getheight() - 60, 30, 30); } public color c = color.white; }
Comments
Post a Comment