java - Applet: Window opens with smaller size -
i have applet program, can run eclipse directly testing. setting window size of applet. but, seeing applet opens smaller window rather actual window size set, , opens proper set size setsize(550, 650);
i couldn't fix why opens smaller window. advise me fix issue?
public class homeapplet extends applet implements actionlistener { public void init() { titlestr = "welcome application home page!"; connectbtn = new button("submit"); connectbtn.addactionlistener(this); add(connectbtn); connectbtn.setbounds(100, 120, 90, 20); connectbtn.setenabled(true); setlayout( null ); setsize(550, 650); sharedimage = new imageicon("sameer15.jpg" ).getimage(); } public void paint (final graphics g) { //super.paint(g); int x = getsize().width; int c1 = x/2; font titlefont = new font("arial", font.bold, 20); g.setfont(titlefont); g.drawstring(titlestr, c1-170, 20); font connectfont = new font("arial", font.bold, 15); g.setfont(connectfont); g.drawstring(connectstr, c1-190, 80); g.drawimage(sharedimage, 100, 100, this); system.out.println("drawimage"); } }
could advise me fix issue?
that applet can tested in appletviewer including applet element in code block @ top of source code.
i.e. change:
public class homeapplet extends applet implements actionlistener to like:
/* <applet code=homeapplet width=550 height=650></applet> */ public class homeapplet extends applet implements actionlistener then compile , run:
prompt> javac homeapplet.java prompt> appletviewer homeapplet.java note
setsize(550, 650); this plain wrong applet. size of applet should set in html or other means. applet (which guest in web page), not have right resize (that guest visiting, , knocking out wall 'a little more space').
questions
these not rhetorical questions. way put is: i expect see answers these questions.
- why code applet? if due spec. teacher, please refer them why cs teachers should stop teaching java applets.
- why awt rather swing? see answer on swing extras on awt many reasons abandon using awt components.
future problems
sharedimage = new imageicon("sameer15.jpg" ).getimage(); you'll begin discover how wrong when see accesscontrolexception in java console when testing in applet viewer command line, or embedded in web page. ..but can deal in separate q&a. ;)
Comments
Post a Comment