java - Load class into frame after button clicked -
sorry bother i'm stuck 3 days problem. need load class initial frame after clicking start button. problem never can done. guess problem in actionlistener method.... can solve it. school project, , teacher doesn't let use swing
or jcomponent
. can give me little help?
the code of first frame is
import java.applet.*; import java.awt.*; import java.awt.event.*; public class frame extends applet { private button v; private button f; private image lo; pergun per = new pergun(); pergun p; public void init() { setsize(400, 550); font myfont = new font("arial", font.bold, 25); v = new button("iniciar"); v.setfont(myfont); v.setbounds((400 / 2) - 35, (550 / 2) - 10, 100, 30); setlayout(null); add(v); v.addactionlistener(new exit()); f = new button("fechar"); f.setvisible(true); f.setbounds(10, 500, 60, 30); f.addactionlistener(new ex()); add(f); } public void start() { p = new pergun(); thread funcao = new thread(); funcao.start(); } public void paint(graphics g) { g.setcolor(color.blue); g.fillrect(0, 0, 400, 550); } class exit implements actionlistener { public void actionperformed(actionevent e) { if (v instanceof button) { per.start(); per.setvisible(true); } } } class ex implements actionlistener { public void actionperformed(actionevent e) { if (f instanceof button) { system.exit(0); } } } }
the second class want load first frame this
import java.applet.*; import java.awt.*; public class pergun extends applet { public void update(){ } public void init () { setbackground(color.red); label i, ii, iii; = new label("indique o número de lâmpadas."); ii = new label("têm todas da mesma potência?"); iii = new label("indique potência:"); i.setbounds(10, 10, 200, 20); ii.setbounds(10, 50, 200, 20); iii.setbounds(10, 100, 200, 20); setlayout(null); add(i); add(ii); add(iii); checkbox w15, w25, w40, w60, w75, w100, w150, wout; w15 = new checkbox("15w"); w25 = new checkbox("25w"); w40 = new checkbox("40w"); w60 = new checkbox("60w"); w75 = new checkbox("75w"); w100 = new checkbox("100w"); w150 = new checkbox("150w"); wout = new checkbox("outra?"); w15.setbounds(20, 120, 50, 50); w25.setbounds(70, 120, 50, 50); w40.setbounds(120, 120, 50, 50); w60.setbounds(170, 120, 50, 50); w75.setbounds(220, 120, 50, 50); w100.setbounds(270, 120, 50, 50); w150.setbounds(320, 120, 50, 50); wout.setbounds(20, 155, 55, 50); add(w15); add(w25); add(w40); add(w60); add(w75); add(w100); add(w150); add(wout); textfield num; num = new textfield(); num.setbounds(250, 10, 100, 20); add(num); choice sn; sn = new choice(); sn.additem(""); sn.additem("sim"); sn.additem("não"); sn.setbounds(250, 50, 100, 20); add(sn); sn.getbackground(); } public void paint(graphics g) { setsize(400, 550); g.setcolor(color.red); g.fillrect(0, 0, 400, 550); } }
thanks time.
Comments
Post a Comment