Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
232 views
in Technique[技术] by (71.8m points)

java - In my Netbeans 8.1, <applet? Tag is not changing the size of the applet , just showing in the same standard size? What should I do?

Please tell why I always getting the same size of the applet?

In my Netbeans 8.1, <applet? Tag is not changing the size of the applet , just showing in the same standard size? What should I do?

This is my code:

package online.book.store;
import java.awt.*;
import java.awt.event.*;
import java.applet.*; 

/*
<applet code="Home_Page" width=300 height=800> </applet>
*/


class SampleFrame extends Frame { SampleFrame(String title) {
    
super(title);

MyWindowAdapter adapter = new MyWindowAdapter(this);

addWindowListener(adapter);

}

public void paint(Graphics g) {

 
g.drawString("This is in frame window", 50, 90);

 

}

 

}

 

class MyWindowAdapter extends WindowAdapter { SampleFrame sampleFrame;

 

public MyWindowAdapter(SampleFrame sampleFrame) { this.sampleFrame = sampleFrame;

 





 

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

define the getPreferredSize() in the frame

@Override
public Dimension getPreferredSize() {
  return( new Dimension( width, height ) );
}

Because Applet is deprecated I would not spend too much time on the subject.
An Applet can't change the size of the frame in which it is executed, regardless of whether it is executed in a browser, Frame window or applet-viewer. You have to set the size of the Frame (see above). The <applet> tags are meanwhile unsupported in nearly every browser.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

1.4m articles

1.4m replys

5 comments

57.0k users

...