I am new to java and having issues.
package components;

import java.awt.*;
import java.awt.event.*;
import javax.swing.*;


/* FrameDemo.java requires no other files. */
public class ContactApp
{
/**
* Create the GUI and show it.  For thread safety,
* this method should be invoked from the
* event-dispatching thread.
*/
private static void createAndShowGUI()
{
//Create and set up the window.
JFrame frame = new JFrame("FrameDemo");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);


JLabel emptyLabel = new JLabel("");
emptyLabel.setPreferredSize(new Dimension(175, 100));
frame.getContentPane().add(emptyLabel, BorderLayout.CENTER);


//Display the window.
frame.pack();
frame.setVisible(true);
}


public static void main(String[] args)
{
//Schedule a job for the event-dispatching thread:
//creating and showing this application's GUI.
javax.swing.SwingUtilities.invokeLater(new Runnable()
{
public void run()
{
createAndShowGUI();
}
});
}
}

I am using this code as an example but when I try to view it all I get is a blank screen. Can someone tell me what to write in my notepad to view the applet. I have this now

<html>
<head>
<title>Dice Game Canvas</title>
</head>
<body>
<h1 align=center>Contact Application</h1>
<center>
<applet name="ContactApp"
code="ContactApp.class"
width=400
height=150>
</applet>
</center>
</body>
</html>

I don't know if this is correct if any one can help. Thank you.

Recommended Answers

All 3 Replies

Hi friend,
Instantiate ContactApp class with an object, make CreateAndShowGUI() method public and call it from run() method. That should solve your problem. Use Netbeans 5.0 and older versions for building better java applicaitons.

I am new to java and having issues...

I am using this code as an example but when I try to view it all I get is a blank screen. Can someone tell me what to write in my notepad to view the applet. I have this now

<html>
<head>
<title>Dice Game Canvas</title>
</head>
<body>
<h1 align=center>Contact Application</h1>
<center>
<applet name="ContactApp"
code="ContactApp.class"
width=400
height=150>
</applet>
</center>
</body>
</html>

I don't know if this is correct if any one can help. Thank you.

Your code is not an applet - it is a standalone frame demo class. You need to code it as an applet if you wish to use it as one:
http://java.sun.com/docs/books/tutorial/deployment/applet/index.html

Thank you for the help I have figured that out now but thank still

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.