Muliple classes in applets
am just starting to learn to use applets, and am a little confused with the structure. after imports, the applet generaly contines with pubic class xyz extend frame for example, which encomases most of the rest of the applet, so does that mean i can only use methords of xzy or can i put classes in side xzy.
If you can understand what i mean, or can point me to an easy resourse on how i should structure, an applet and how i should layout different class's inside the applet i would be great full. Exaclty 5 duke doller greatfull (cos thats what i got left).
Here's an example to illustrate.
You can just as well put the two outer classes inside the applet. If you do then you won't need to pass a reference into the ControlPanel class to call methods in the DisplayPanel class. Instead you would put the DisplayPanel instance variable in class scope. In java:
public class ExampleApplet extends JApplet
DisplayPanel displayPanel;
public void init()
displayPanel = new DisplayPanel();
class DisplayPanel...
class ControlPanel extends JPanel
JComboBox outerColor, innerColor;
public ControlPanel(DisplayPanel dp)
// create components for panel
public static void main...
}To call methods or get access to variables in another class you need a way to get a reference to that class.
One benefit in keeping the classes separated is that you can isolate your event code, your drawing code and your gui display code. This can make it easier to conceptualize and maintain.
/* <applet code="ExampleApplet" width="400" height="400"></applet>
* use: >appletviewer ExampleApplet.java
import java.awt.*;
import java.awt.event.*;
import java.awt.geom.*;
import java.util.Random;
import javax.swing.*;
public class ExampleApplet extends JApplet
public void init()
DisplayPanel displayPanel = new DisplayPanel();
ControlPanel control = new ControlPanel(displayPanel);
Container cp = getContentPane();
cp.setLayout(new BorderLayout());
cp.add(control, "North");
cp.add(displayPanel);
* Convenience method so you can run applet from command line
public static void main(String[] args)
JApplet applet = new ExampleApplet();
JFrame f = new JFrame();
f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
f.getContentPane().add(applet);
f.setSize(400,400);
f.setLocation(200,200);
applet.init();
applet.start();
f.setVisible(true);
class DisplayPanel extends JPanel
Random seed;
Color bgColor, outerColor, innerColor;
public DisplayPanel()
seed = new Random();
bgColor = Color.white;
outerColor = Color.blue;
innerColor = Color.orange;
setBackground(bgColor);
protected void paintComponent(Graphics g)
super.paintComponent(g);
Graphics2D g2 = (Graphics2D)g;
g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
RenderingHints.VALUE_ANTIALIAS_ON);
int w = getWidth();
int h = getHeight();
int dia = Math.min(w, h)/4;
g2.setPaint(outerColor);
g2.fill(new Ellipse2D.Double(w/2 - dia/2, h/2 - dia/2, dia, dia));
g2.setPaint(innerColor);
g2.fill(new Ellipse2D.Double(w/2 - dia/4, h/2 - dia/4, dia/2, dia/2));
public void setBackground()
Color color = new Color(seed.nextInt(256), seed.nextInt(256), seed.nextInt(256));
setBackground(color);
repaint();
public void setOuterColor(Color color)
outerColor = color;
repaint();
public void setInnerColor(Color color)
innerColor = color;
repaint();
class ControlPanel extends JPanel
DisplayPanel displayPanel;
JComboBox outerColor, innerColor;
public ControlPanel(DisplayPanel dp)
displayPanel = dp;
// create components for panel
JButton bgColor = new JButton("background");
bgColor.addActionListener(new ActionListener()
public void actionPerformed(ActionEvent e)
displayPanel.setBackground();
String[] outerColorNames = {
"blue", "yellow", "cyan", "magenta"
outerColor = new JComboBox(outerColorNames);
String[] innerColorNames = {
"orange", "red", "green", "pink"
innerColor = new JComboBox(innerColorNames);
ColorListener l = new ColorListener();
outerColor.addActionListener(l);
innerColor.addActionListener(l);
// layout components
setLayout(new GridBagLayout());
GridBagConstraints gbc = new GridBagConstraints();
gbc.insets = new Insets(2,2,2,2);
gbc.weightx = 1.0;
add(bgColor, gbc);
gbc.anchor = gbc.EAST;
add(new JLabel("outer"), gbc);
gbc.anchor = gbc.WEST;
add(outerColor, gbc);
gbc.anchor = gbc.EAST;
add(new JLabel("inner"), gbc);
gbc.anchor = gbc.WEST;
add(innerColor, gbc);
class ColorListener implements ActionListener
Color[] outerColors = {
Color.blue, Color.yellow, Color.cyan, Color.magenta
Color[] innerColors = {
Color.orange, Color.red, Color.green, Color.pink
public void actionPerformed(ActionEvent e)
JComboBox combo = (JComboBox)e.getSource();
int index = combo.getSelectedIndex();
if(combo == outerColor)
displayPanel.setOuterColor(outerColors[index]);
if(combo == innerColor)
displayPanel.setInnerColor(innerColors[index]);
}
Similar Messages
-
Looking for a Java USA Map class or applet
Hi,
I need to display a gif (or applet) of the USA and be able to color states different colors. Does anyone know of a simple class or applet that will do this?Email me
[email protected] -
Please Help !!! Problem relaoding classes in applet
I would like to know is it possible to dynamically load the classes in applet. What i mean is if
the applet has already loaded class A, can I load it again from the server instead of using the
cache copy in the browser in the client machine? If it is possible to be done, how can it be done? Can any Java guru give me some code on how to achieve this? Help will be highly appreaciated.
[email protected]You can load any classes you want just by simply calling them from your applet. Just make sure they are accessable to the applet(in the same directory, for example).
MyClass newClass=new MyClass();
And use it. -
Java Applet Error ClassFormatError, Incompatible value 1347093766 in class file Applet
So when i run my applet it yhows this error:
Java Applet Error ClassFormatError, Incompatible value 1347093766 in class file Applet
how can i fix this?
thanksstill didn't fix the problem. please help
-
Java application with classes to Applet?
Hello,
First, I'm a Java junior, but I can make efforts to analyse and understand code.
I saw an interesting open-source multiplayer poker java application: [JiBi's Hold'Em|http://sourceforge.net/projects/jibisholdem/]
I would like to try to add it as an Applet on my server, but I have some questions.
1- Do you think it is possible to make it fully works as an Applet (eg: through a proxy), as it seems to use a specific protocol and many classes?
2- I tried the idea of GumB: http://forums.sun.com/thread.jspa?threadID=390846&start=13&tstart=0
with getContentPane().add( new javaApp().getContentPane()but I have the following error message:
I also tried with imports (import holdem.core.Card;etc) and with HoldEmClientGUI().getContentPane() or holdem.gui.HoldEmClientGUI().getContentPane()
D:\JiBisHoldem\src\holdem\gui\HoldEmApp.java:7: cannot find symbol
symbol : class HoldEmClientGUI
location: class HoldEmApp
getContentPane().add( new HoldEmClientGUI().getContentPane() );
^
1 errorAm I close or really far from a working result?
Thanks
John.The above way seems to have the same result as getContentPane().add( new javaApp().getContentPane().
Here is my HoldEmClientGUI.java (I have commented unused lines like title):
package holdem.gui;
import holdem.core.Card;
import holdem.core.Choice;
import holdem.core.Player;
import holdem.gui.interfaces.ClientGUIInterface;
import holdem.gui.menu.MainMenuBar;
import holdem.gui.panel.PokerChoiceListPane;
import holdem.gui.panel.PokerMainPane;
import holdem.gui.panel.PokerPlayerPane;
import java.awt.BorderLayout;
import java.io.IOException;
import java.util.ArrayList;
import java.util.HashMap;
import javax.swing.ImageIcon;
import javax.swing.JFrame;
import javax.swing.JApplet;
import sun.audio.AudioPlayer;
import sun.audio.AudioStream;
import tools.AppProperties;
import java.applet.*;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class HoldEmClientGUI extends JApplet {
public static void main(String[] args) {
HoldEmClientGUI app = new HoldEmClientGUI();
app.init();
app.start();
public void init()
AppletContext ac = null;
try
ac = getAppletContext();
catch(NullPointerException npe)
//new HoldEmClientGUIFrame(ac);
new HoldEmClientGUIFrame();
class HoldEmClientGUIFrame extends JFrame implements ClientGUIInterface {
private static final long serialVersionUID = 1L;
private String m_mainTitle = "";
private String m_title1 = "";
private String m_title2 = "";
private HashMap<Integer, PokerPlayerPane> m_playerPaneList = null;
private PokerMainPane m_pokerMainPane = null;
private MainMenuBar m_pokerMainMenuBar = null;
private PokerChoiceListPane m_pokerChoiceListPane = null;
//AppletContext ac;
//HoldEmClientGUI(AppletContext ac) {
HoldEmClientGUIFrame() {
//super();
//this.ac = ac;
//Set Icon
//setIconImage(new ImageIcon(getClass().getResource(AppProperties.getInstance().getProperty("holdem.images.icon.logo"))).getImage());
m_mainTitle = AppProperties.getInstance()
.getProperty("holdem.config.title")
+ " - v"
+ AppProperties.getInstance().getProperty(
"holdem.config.version");
//refreshTitle();
// adding PokerTable
getContentPane().add(getPokerMainPane(), BorderLayout.CENTER);
getContentPane().add(getPokerChoiceListPane(), BorderLayout.SOUTH);
getContentPane().add(getPokerMainMenuBar(), BorderLayout.NORTH);
// init playerPaneList
m_playerPaneList = new HashMap<Integer, PokerPlayerPane>();
//setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
// setSize(200, 100);
/* Add the window listener */
addWindowListener(new WindowAdapter()
public void windowClosing(WindowEvent evt)
dispose();
if (AppletApplicationFrame.this.ac == null)
System.exit(0);
setVisible(true);
pack();
private void refreshTitle(){
//setTitle(m_mainTitle+m_title1+m_title2);
private PokerMainPane getPokerMainPane() {
if (m_pokerMainPane == null) {
m_pokerMainPane = new PokerMainPane();
return m_pokerMainPane;
private PokerChoiceListPane getPokerChoiceListPane() {
if (m_pokerChoiceListPane == null) {
m_pokerChoiceListPane = new PokerChoiceListPane();
return m_pokerChoiceListPane;
private MainMenuBar getPokerMainMenuBar() {
if (m_pokerMainMenuBar == null) {
m_pokerMainMenuBar = new MainMenuBar();
return m_pokerMainMenuBar;
public void addPlayer(Player player) {
PokerPlayerPane playerPane = new PokerPlayerPane();
playerPane.initPlayer(player.getId(), player.getSeatNumber(), player
.getNickname(), player.getStack(), player.getPlayerType());
getPokerMainPane().addOnSeat(playerPane, player.getSeatNumber());
m_playerPaneList.put(player.getId(), playerPane);
public void setPlayerCardHighlighted(boolean highlighted, int playerId,
int cardNumber) {
PokerPlayerPane playerPane = getPlayerPaneByPlayerID(playerId);
if (playerPane != null) {
playerPane.setCardHighlighted(highlighted, cardNumber);
public void setTableCardHighlighted(boolean highlighted, int cardNumber) {
m_pokerMainPane.setCardHighlighted(highlighted, cardNumber);
public void setAllCardsHighlighted(boolean highlighted) {
ArrayList<PokerPlayerPane> playerPaneList = new ArrayList<PokerPlayerPane>(
m_playerPaneList.values());
for (int playerCounter = 0; playerCounter < playerPaneList.size(); playerCounter++) {
playerPaneList.get(playerCounter)
.setCardHighlighted(highlighted, 0);
m_pokerMainPane.setCardHighlighted(highlighted, 0);
public Choice displayChoices(ArrayList<Choice> choiceList) {
return getPokerChoiceListPane().displayChoices(choiceList);
public void displayAsyncMsg(String msg) {
getPokerMainPane().displayTempoMsg(msg);
public int getBetValue() {
return getPokerChoiceListPane().getBetValue();
public void addCardToPlayer(int playerId, Card card) {
PokerPlayerPane playerPane = getPlayerPaneByPlayerID(playerId);
if (playerPane != null) {
playerPane.addCard(card);
public void addCardToTable(Card card) {
getPokerMainPane().addCardToTable(card);
public void removeCardsFromPlayer(int playerId) {
PokerPlayerPane playerPane = getPlayerPaneByPlayerID(playerId);
if (playerPane != null) {
playerPane.removeCards();
public void removeCardsFromPlayers() {
ArrayList<PokerPlayerPane> playerPaneList = new ArrayList<PokerPlayerPane>(
m_playerPaneList.values());
for (int playerCounter = 0; playerCounter < playerPaneList.size(); playerCounter++) {
playerPaneList.get(playerCounter).removeCards();
public void removeCardsFromTable() {
getPokerMainPane().removeCards();
private PokerPlayerPane getPlayerPaneByPlayerID(int playerID) {
PokerPlayerPane foundPlayerPane = (PokerPlayerPane) m_playerPaneList
.get(playerID);
return foundPlayerPane;
public void setButton(int seatNumber, int buttonType) {
m_pokerMainPane.setButton(seatNumber, buttonType);
public void setConnectionStatus(boolean isConnected, String nickname) {
m_pokerMainMenuBar.setConnectionStatus(isConnected);
m_title1 = " - " + nickname;
if (isConnected) {
m_title1+=" is Connected";
} else {
m_title1+=" is not Connected";
refreshTitle();
public void setPot(int potValue) {
getPokerMainPane().setPot(potValue);
public void setPlayerStack(int playerID, int newStack) {
PokerPlayerPane playerPane = getPlayerPaneByPlayerID(playerID);
if (playerPane != null) {
playerPane.setStack(newStack);
public void setCurrentBetValue(int playerID, int betValue) {
PokerPlayerPane playerPane = getPlayerPaneByPlayerID(playerID);
if (playerPane != null) {
playerPane.setCurrentBet(betValue);
public void setPlayerAction(int playerID, int PLAYER_ACTION) {
PokerPlayerPane playerPane = getPlayerPaneByPlayerID(playerID);
if (playerPane != null) {
playerPane.setAction(PLAYER_ACTION);
public void playSound(int ACTION) {
String soundPath = "";
switch (ACTION) {
case ClientGUIInterface.ACTION_ALLIN: {
soundPath = AppProperties.getInstance().getProperty(
"holdem.sounds.chips.allin");
break;
case ClientGUIInterface.ACTION_BET: {
soundPath = AppProperties.getInstance().getProperty(
"holdem.sounds.chips");
break;
case ClientGUIInterface.ACTION_CALL: {
soundPath = AppProperties.getInstance().getProperty(
"holdem.sounds.chips");
break;
case ClientGUIInterface.ACTION_RAISE: {
soundPath = AppProperties.getInstance().getProperty(
"holdem.sounds.chips");
break;
case ClientGUIInterface.ACTION_PAY_SMALL_BLIND: {
soundPath = AppProperties.getInstance().getProperty(
"holdem.sounds.chips");
break;
case ClientGUIInterface.ACTION_PAY_BIG_BLIND: {
soundPath = AppProperties.getInstance().getProperty(
"holdem.sounds.chips");
break;
case ClientGUIInterface.ACTION_CHECK: {
soundPath = AppProperties.getInstance().getProperty(
"holdem.sounds.check");
break;
case ClientGUIInterface.ACTION_FOLD: {
soundPath = AppProperties.getInstance().getProperty(
"holdem.sounds.fold");
break;
case ClientGUIInterface.ACTION_DEAL_CARDS: {
soundPath = AppProperties.getInstance().getProperty(
"holdem.sounds.card");
break;
case ClientGUIInterface.ACTION_REMOVE_CARDS: {
soundPath = AppProperties.getInstance().getProperty(
"holdem.sounds.remove_cards");
break;
default: {
if (soundPath != null && !soundPath.trim().equals("")) {
try {
AudioPlayer.player.start(new AudioStream(getClass()
.getResource(soundPath).openStream()));
} catch (IOException ioe) {
System.err.println("Unable to play sound:\n" + soundPath
+ "\n\n" + ioe);
private void displayBlindValues(int curSB, int curBB, int nextSB, int nextBB){
//m_title2=" - "+curSB+"/"+curBB+" (next values "+nextSB+"/"+nextBB+")";
//refreshTitle();
public void raiseBlinds(int curSB, int curBB, int nextSB, int nextBB){
displayBlindValues(curSB,curBB,nextSB,nextBB);
}The error when calling HoldEmClientGUI.class (I have 2 files HoldEmClientGUI.class and HoldEmClientGUIFrame.class, is it normal?):
java.lang.VerifyError: (class: holdem/gui/menu/MainMenuBar, method: handleSettingsItem signature: ()V) Incompatible argument to function
at holdem.gui.HoldEmClientGUIFrame.getPokerMainMenuBar(HoldEmClientGUI.java:145)
at holdem.gui.HoldEmClientGUIFrame.<init>(HoldEmClientGUI.java:95)
at holdem.gui.HoldEmClientGUI.init(HoldEmClientGUI.java:54)
at sun.applet.AppletPanel.run(Unknown Source)
at java.lang.Thread.run(Unknown Source)MainMenuBar.java:
import holdem.gui.dialog.ClientInputDialog;
import holdem.gui.dialog.ServerInputDialog;
import holdem.gui.dialog.SettingsDialog;
private void handleSettingsItem() {
new SettingsDialog(getHoldEmClientGUI());
private HoldEmClientGUI getHoldEmClientGUI() {
HoldEmClientGUI gui = null;
Container curContainer = this;
do {
curContainer = curContainer.getParent();
} while (curContainer instanceof Container
&& !(curContainer instanceof HoldEmClientGUI));
if (curContainer instanceof HoldEmClientGUI) {
gui = (HoldEmClientGUI) curContainer;
return gui;
}I think the problem comes from private HoldEmClientGUI getHoldEmClientGUI() but I don't know what is wrong in it.
Edited by: Quezako on Oct 14, 2008 7:51 AM -
So im just starting java, about 12 weeks in.
So in my class we are getting started with objects. What i want to do is create a class called car, and have it create a new car and draw images loaded, and then have the tires rotate, there are 2 images,
the car base and the tires.
I know how to display images in applets, but i dont know how to define the images in the objects class and then draw them from the class.I get errors with this code from my car class
import java.applet.*;
public class car extends Applet{
* @param args
private String model;
private int passangers;
private double gas,speed;
private Image tire;
private MediaTracker tr;
tr = new MediaTracker(this);
tire = getImage(getCodeBase(), "tire.png");
tr.addImage(tire,0);
public car(String id, int pass, double tank)
model=id;
passangers=pass;
gas=tank;
public car()
model="";
passangers=0;
gas=0;
}I get errors on these lines
private Image tire;
private MediaTracker tr;
tr = new MediaTracker(this);
tire = getImage(getCodeBase(), "tire.png");
tr.addImage(tire,0);errors
Severity and Description Path Resource Location Creation Time Id
Image cannot be resolved to a type Car Game car.java line 13 1197077768237 1745
MediaTracker cannot be resolved to a type Car Game car.java line 14 1197077768238 1746
Return type for the method is missing Car Game car.java line 16 1197077768239 1750
Syntax error on token ";", { expected after this token Car Game car.java line 14 1197077768238 1747
Syntax error on token "(", delete this token Car Game car.java line 17 1197077768239 1752
Syntax error on token "0", invalid FormalParameter Car Game car.java line 17 1197077768239 1753
Syntax error on token(s), misplaced construct(s) Car Game car.java line 15 1197077768238 1748
Syntax error on token(s), misplaced construct(s) Car Game car.java line 16 1197077768239 1749
Syntax error on tokens, delete these tokens Car Game car.java line 16 1197077768239 1751
The serializable class car does not declare a static final serialVersionUID field of type long Car Game car.java line 4 1197077768237 1744
The serializable class main does not declare a static final serialVersionUID field of type long Applet main.java line 5 1196990860997 1682
The serializable class main does not declare a static final serialVersionUID field of type long Car Game main.java line 5 1197077768196 1743
The serializable class ShowImage does not declare a static final serialVersionUID field of type long Display JPEG/src ShowImage.java line 4 1196488911896 1393Edited by: jasonpeinko on Dec 7, 2007 5:42 PM -
Rmi inner class extending Applet is it possible
I have created four classes for my RMI program
1>hellointerface
2>helloserver
3>register
4>helloclient
hellointerface has only one Abstract Method
public String sayhello()throws java.rmi.RemoteException;
The problem is with my helloserverclass. my helloserver class needs to extend UnicastRemoteObject however i want to do it by using
UnicastRemoteObject.exportObject(this);
There is no problem with the coplilation of code of this class.
classregister is what getting effected if i use exportObject(this)function.
the problem is the command prompt where i run java register
appers like this
Object created
Object ready for use
and than the register stop running .The same console is ready for
running other Program where as in the case of Rmi the class that register the object using rebind() method must keep on running in the dos prompt
my register class looks something like this
try
helloserver object=new helloserver()
System.out.println("Object created");
Naming.rebind("/helloserver",object);
System.out.println("Object ready for use");
my server side code is something like this
public class helloserver implements hellointerface
public helloserver throws java.rmi.RemoteException
UnicastRemoteObject.exportObject(this);
//and the only method defined is as follows
public String sayhello()throws java.rmi.RemoteException
return "Thank u for reading this the current System time is "+new Date();
the client side is having a Applet which display this Message
I know this is a simple program but plz help me out
Thank uSorry xHacker I didn't see this one before but it is another multi-post of
http://forum.java.sun.com/thread.jspa?threadID=644864&tstart=0 -
Problem when used InetAddress class in Applet
Hi all.
I'DongPG from Vietnam.
I have a question'How to get IP that different from IP default "127.0.0.1" address'.
I've built an applet where i used InetAddress class to get browser'IP follow:
InetAddress localIP = InetAddress.getLocalHost();
String strIP=localIP.getHostAddress();
I used JBuilder to build applet. It's gotten IP right. Ex:strIP='192.168.100.1'
But when i used browser link to my Applet in WebServer, it only return strIP='127.0.0.1'
Thank a lot!Wrong forum and cross posted as well.
-
Re: Including JMF classes in Applet archive
Two solutions:
In the easy and loadheavy you include into your applet loading html:
START HTML
<applet "com.company.myapplets.TheApplet" archive="jarcontainingTheApplet.jar, jmf.jar" width=320 height=240>
the jmf.jar is the one distrubuted w. JMF.
In a specialized version for faster loads your could build the jmf classes needed into your own jar.
regardsHave tried this... Ona any machine without jmf, java console reports exceptions such as...
com.ms.security.SecurityExceptionEx[com/sun/media/util/Registry.<clinit>]: Unable to access system property: java.class.path
com.ms.security.SecurityExceptionEx[com/sun/media/IESecurity.loadLibrary]
com.ms.security.SecurityExceptionEx[com/sun/media/util/MediaThread.getRootThreadGroup]: Illegal ThreadGroup access.
I've also tried with a customized jmf.jar and with jmf.jar. It still won't run.
html is..............
<applet code="TVApplet.class" archive="tvapplet.jar, jmfcustom.jar" width=587 height=510>
<param name=file value="Bear3.mpg">
</applet>
...please help -
Need help with classes in Applets and drawing buildings.
I'm trying to create an Applet that draws a starfield (I got that right) and then searches for any parameters in the Applet tag. The Applet then draws as many buldings as there are parameters in the Applet tag, and uses the number in the parameter as the height. I have it working OK, but it won't draw the buildings. Here is me code:
import java.applet.Applet;
import java.awt.*;
import java.awt.geom.*;
import java.util.*;
import javax.swing.*;
public class Skyline extends Applet {
public void init() {
setBackground(Color.black);
public void paint(Graphics g) {
Graphics2D pen = (Graphics2D) g;
Random generator = new Random();
Stars starField = new Stars();
starField.drawStars(pen, getWidth(), getHeight());
int n = 1;
String param = null;
while((param = getParameter("param" + n)) != null) {
n++;
int startX = 0;
int startY = getHeight();
int height = 0;
int width = getWidth() / (n + 2);
Building structure = new Building();
structure.drawBuilding(pen, height, width, startX, startY, n);
class Stars {
public void drawStars(Graphics2D pen, int Width, int Height) {
Random generator = new Random();
int runs = 1;
while (runs <= 1000) {
int Xcord = generator.nextInt(Width - 3);
int Ycord = generator.nextInt(Height - 3);
Ellipse2D.Double star
= new Ellipse2D.Double(Xcord, Ycord, 3, 3);
pen.setColor(Color.white);
pen.fill(star);
runs++;
class Building {
public void drawBuilding(Graphics2D pen, int height, int width, int startX, int startY, int n) {
Random generator = new Random();
int n2 = 1;
int runs = 1;
String input = "";
int red = generator.nextInt(100),
green = generator.nextInt(100),
blue = generator.nextInt(100);
pen.setColor(new Color(red, green, blue));
while (runs <= n) {
input = getParameter("building" + n2);
height = Integer.parseInt(input);
height = startY - height;
Rectangle building = new Rectangle(startX, startY, height, width);
pen.fill(building);
startY = startY + width;
n2++;
runs++;
Can anyone help me?That didn't work, so I looked at the code again and found some errors. I decided to rewrite it, here is the updated code...
import java.applet.Applet;
import java.awt.*;
import java.awt.geom.*;
import java.util.*;
import javax.swing.*;
public class Skyline extends Applet {
public void init() {
setBackground(Color.black);
public void paint(Graphics g) {
Graphics2D pen = (Graphics2D) g;
Random generator = new Random();
Stars starField = new Stars();
starField.drawStars(pen, getWidth(), getHeight());
Building structure = new Building();
structure.drawBuilding(pen);
class Stars {
public void drawStars(Graphics2D pen, int Width, int Height) {
Random generator = new Random();
int runs = 1;
while (runs <= 1000) {
int Xcord = generator.nextInt(Width - 3);
int Ycord = generator.nextInt(Height - 3);
Ellipse2D.Double star
= new Ellipse2D.Double(Xcord, Ycord, 3, 3);
pen.setColor(Color.white);
pen.fill(star);
runs++;
class Building {
public void drawBuilding(Graphics2D pen) {
Random generator = new Random();
int n = 1;
int n2 = 1;
int runs = 1;
String input = "";
String param = "";
while ((param = getParameter("building" + n)) != null) {
n++;
int height = getHeight();
int width = getWidth();
int startX = 0;
int startY = height;
int red = generator.nextInt(100),
green = generator.nextInt(100),
blue = generator.nextInt(100);
pen.setColor(new Color(red, green, blue));
while (runs <= n) {
height = getHeight();
input = getParameter("building" + n2);
height = Integer.parseInt(input);
height = startY - height;
Rectangle building = new Rectangle(startY, startX, height, width);
pen.fill(building);
startX = startX + width;
n2++;
runs++;
I can get it to draw one large black building, but that's it. -
I have written an applet that does a mathematical operation on numbers then shows a diagram on the clicking of a button.
On the clicking of the button I removed the previous two panels and repainted the GUI with the diagram, created using a sub class/ The class header and constuctor is shown below for the sub class.
In netbeans, using applet viewer this works.
Yet for some reason when the applet code is used in a web page the main applet comes up fine and is operational but when clicking the diagram button nothing happens.
II would appreciate any help going?
Thanks
public class VennChart extends JPanel
/**provides a venn diagram of fucntion
*@param g is graphics component
public void paintComponent(Graphics g)
//frame initialisation
super.paintComponent(g);
//code to draw diagram
if(ae.getSource()==graph)
pane.remove(holder);
pane.remove(status);
pane.repaint();
pane.add(exit, "North");
VennChart chart = new VennChart();
temp = chart; //temporary JPanel variable to hold diagram
pane.add(temp, "Center");
pane.validate();
}What error message do you get in the java console?
-
Runtime execution of a Class from applet.....
Hi all,
I have a applet in a jar(say A.jar) and it is signed. One more jar(say B.jar) is created and it contains a class that has to be executed using Runtime.exec() from the applet (in other jar -> A.jar). Both jars present in server and jar list is mentioned using <PARAM NAME=CACHE_ARCHIVE VALUE="...."> tag where the VALUE is assigned with list of jar names.
So how to execute a Class at Runtime present in one jar from a applet present in other jar.
Please help....
Thanx,
Sonithx Clemens... thx for the reply...
Here i am not accessing a applet from another applet. I want to Run a Java Application from a Applet (using Runtime class). How to do this? Here the Java Application class exist in a seperate jar other than the jar which holds Applet class. Both jars are signed and both exist in server.
thx,
Soni. -
Html class with applet tag support ?
Hello,
I would like to load in a swing application, an html file which contains the tag 'applet'. JEditorPane doesn't support it.
Anyone know of an another class ?
Thanks
Nathalie OBADIAIf all else fails you can get the source code and look to see how appletviewer is implemented. It probably just calls some internal sun java classes.
-
i want to ask that if my applet have more than one class, are all classes loaded to client machine autometically or i have to do it by another way (if yes how) ?
Put all the stuff into a single zip or preferably a single jar.
-
Set class for applet in plug-in
Hi All,
I have an applet download from web server and running on plug-in.
my html like this:
<applet
code = "com.test.applet1.class"
name = "test"
width = "800"
height = "450"
hspace = "0"
vspace = "0"
align = "top"
>
And I put the com\test\applet1.class in the same directory with the html file. My applet will use lots of libs. For better performance and this is an intranet based application so I put all the libs in the client machine under jre1.3.0\lib\ext. But every time there are class not found errror for the relaeated libs.
Is there any rules for plug-in classpath setup.
Thanks for your help
Scottdunno if this works but create a jar file which includes a the required lib files and keep it in the same dir as the original class file and add a line in ur applet
<applet code= .... archive=NameofJar.jar heigt...>
sairam
Maybe you are looking for
-
How can I unlink my iPhone from an apple id?
I tried to download the iOS 8 update, but it told me i didn't have enough storage and there was an error so i clicked the okay button and unplugged my phone. Then it had that screen that said plug into your iTunes, so i plugged it in and said i had t
-
My computer is Win8.1 64bit. Where can i download Adobe acrobat DC 64 bit? The application manager always download 32 bits application for me! (I tryed PS and AI just now. the application manager installed 64bits PS and AI. Why it can't find a 64bit
-
Some incoming calls and messages display the phone number instead of name
I recently upgraded from a Blackberry to an iPhone 4s. When I receive a call or SMS on the 4s it often displays only the phone number instead of the name at the top of the screen even though I the correct name and phone number are entered the correct
-
Perfromance problem when using MDX queries in Crystal
Dear All, I am using Crystal reports together with an MDX query from the BI system. When I run the report in the Web then it takes 60 seconds to get results. When I use this query through MDX into a crystal report the query runs very long and in most
-
Hi, we have three different mail domain hosted in different hosting companies, currently we need all mail domain should be work in exchange 2013. so we configured four servers 2 CAS server (RRDNS) 2 MB server with DAG, domains are hala.local hala.com