Results 1 to 3 of 3
  1. #1
    3dprogger is offline Member
    Join Date
    Jan 2011
    Posts
    1
    Rep Power
    0

    Angry 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

    Java 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();  
       }
      }
    }
    HTML Code
    XML 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>
    Hope you know something about my problem
    Last edited by 3dprogger; 01-06-2011 at 09:35 AM.

  2. #2
    Arthur123 is offline Member
    Join Date
    Jan 2011
    Posts
    11
    Rep Power
    0

    Default

    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).

  3. #3
    Jodokus's Avatar
    Jodokus is offline Senior Member
    Join Date
    Jan 2011
    Location
    Amsterdam, the Netherlands
    Posts
    230
    Rep Power
    4

    Default

    @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

  1. Last JLabel I add to JPanel doesnt show up
    By Ambergahill in forum New To Java
    Replies: 6
    Last Post: 01-29-2014, 09:07 PM
  2. combobox doesnt show!
    By LennyKosmos in forum New To Java
    Replies: 2
    Last Post: 10-26-2010, 09:07 PM
  3. Replies: 7
    Last Post: 09-28-2010, 01:17 AM
  4. doesnt show exact size
    By clydedoris in forum NetBeans
    Replies: 3
    Last Post: 07-13-2010, 07:59 AM
  5. JTable doesnt show columun names!
    By phil128 in forum AWT / Swing
    Replies: 3
    Last Post: 03-08-2009, 11:39 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •