1

I am writing a Java Swing Application. It consists of a graphing tool which I added as a library. It works fine as a desktop application. However, I'm trying to convert this application into an applet and the graphing frame won't come up on the browser. The code for the invoking the graphing frame is:

double x[] = {1,2,3,4,5,6,7,8};
double y[] = {1,0,1,0,1,0,1,0};        
plot.addLinePlot("plot", Color.BLUE, x, y);    
JFrame frame = new JFrame("A Plot Panel");
frame.setSize(1400, 730);
frame.setContentPane(plot);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setVisible(true);

I typed the same lines in the applet but it won't work in the browser. How do I make this work in an applet?

Paul Samsotha
  • 205,037
  • 37
  • 486
  • 720
  • My monitor is only 1366 wide. Am I excluded from seeing the entire frame? – Paul Samsotha Mar 06 '14 at 10:49
  • See [here](http://stackoverflow.com/a/7441654/2587435), [here](http://stackoverflow.com/a/2435305/2587435) see if they help. – Paul Samsotha Mar 06 '14 at 10:52
  • @peeskillet thats just a case scenario –  Mar 06 '14 at 13:23
  • @AndrewThompson to make it available for over a network –  Mar 06 '14 at 13:47
  • For deploying Java desktop apps. (e.g. based on `JFrame`) over a network, the best option is usually to install the app. using [Java Web Start](http://stackoverflow.com/tags/java-web-start/info). JWS works on Windows, OS X & *nix. – Andrew Thompson Mar 06 '14 at 14:21

2 Answers2

1

extend the Applet class, add all your gui elements accordingly, you can not show a frame in a browser applet is provided as a main container as Frame or JFrame in desktop application.

example:-

    public class MyApplet extends Applet{
    public void paint(Graphics g){
            /* Your applet code here
               */
            g.setColor(Color.red);
            g.drawRect(20,20,200,180);
        }
    }
Ankur Kumawat
  • 446
  • 5
  • 21
0

Put all you gui elements in a panel and add to applet/frame as appropriate

onesixtyfourth
  • 744
  • 9
  • 30