Results 1 to 3 of 3
- 01-06-2011, 08:31 AM #1
Member
- Join Date
- Jan 2011
- Posts
- 1
- Rep Power
- 0
Applet doesnt start or it doesnt show
Hello guys, first of all Im a confirmed C/C++ Programmer. For the school I have to do some homework. This homework should be done in Java Applet:mad:
I know a bit about Java, but it's illogical and im mystified.
The homework is to visualize a Black Jack Game
My problem is that the applet isnt showing a label or button and so on.
At the start it rests white and that's it.
My applet code
HTML CodeJava Code:import java.awt.*; import java.awt.event.*; import java.applet.*; public class siebzehnvier_applet extends Applet implements ActionListener{ TextField sname1,sname2,sname3=new TextField("",10); Button a,b,c; Label label1; int anzahl = 3; String [] spielernamen = new String[anzahl]; Runde r; public void init(){ setLayout (null); setBackground(new java.awt.Color(231,231,231)); //setBounds(x,y,Breite, Höhe) label1 = new Label("Spielernamen eingeben: "); label1.setBounds(700,50, 20, 10); add(label1); setVisible(true); sname1.setEditable(true); sname1.addActionListener(this); sname1.setBounds(50,50, 30, 12); add(sname1); sname1.setText("Spielername 1"); sname2.setEditable(true); sname2.addActionListener(this); sname2.setBounds(100,50, 30, 12); add(sname2); sname2.setText("Spielername 2"); sname3.addActionListener(this); sname3.setEditable(true); sname3.setBounds(150,50, 30, 12); add(sname3); sname3.setText("Spielername 3"); a = new Button("Annehmen"); a.addActionListener(this); add(a); b = new Button("Spielen"); b.addActionListener(this); add(b); c = new Button("Beenden"); c.addActionListener(this); add(c); validate(); } public void actionPerformed(ActionEvent e){ Object source= e.getSource(); if (source==a) { spielernamen[0]=sname1.getText(); spielernamen[1]=sname2.getText(); spielernamen[2]=sname3.getText(); if ((spielernamen[0]!="Spielername 1")&&(spielernamen[1]!="Spielername 2")&&(spielernamen[2]!="Spielername 3")) { r = new Runde(anzahl, spielernamen); } if (source==b) { r.Spielstart(); } if (source==c) { System.exit(0); } repaint(); } } }
Hope you know something about my problemXML Code:<html> <head> <title>Siebzehn und Vier Simulation</title> </head> <body text="#000000" bgcolor="#009900" link="#FF0000" alink="#FF0000" vlink="#800000"> <div align="center"> <applet code=siebzehnvier_applet.class width=800 height=600> </applet> </div> </body> </html>
Last edited by 3dprogger; 01-06-2011 at 08:35 AM.
- 01-06-2011, 10:14 PM #2
Member
- Join Date
- Jan 2011
- Posts
- 11
- Rep Power
- 0
I've just started applets myself, & I'm curious: are you sure you don't have to put the "" around the myapplet.class in the HTML? Because I do on my site... I'm not sure if that has any effects though, so try it... (if you haven't already).
- 01-07-2011, 07:03 PM #3
@Arthur: the """" are the thing to do, but HTML is very forgiving. It's not the reason.
@Progger: Java is not forgiving, so forget C. To get you started:
-use a proper IDE: you need a debugger.
-classnames start with capitals (convention)
-mark global fields as private (safer)
-sname1 and 2 are declared but not initialized ->nullpointer-Exception
-Stringcomparising in java is done with equals(), not ==.
-Your comparisonslist is not complete: what if Spieler[0].equals(Spieler[3])?
-Comparing with String-literals is very demanding on your users.
Similar Threads
-
Last JLabel I add to JPanel doesnt show up
By Ambergahill in forum New To JavaReplies: 5Last Post: 11-15-2010, 10:37 PM -
combobox doesnt show!
By LennyKosmos in forum New To JavaReplies: 2Last Post: 10-26-2010, 08:07 PM -
Method Doesnt turn negative number 0 and doesnt return 3
By anonb in forum New To JavaReplies: 7Last Post: 09-28-2010, 12:17 AM -
doesnt show exact size
By clydedoris in forum NetBeansReplies: 3Last Post: 07-13-2010, 06:59 AM -
JTable doesnt show columun names!
By phil128 in forum AWT / SwingReplies: 3Last Post: 03-08-2009, 10:39 PM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks