Results 1 to 6 of 6
  1. #1
    MrSulfat is offline Member
    Join Date
    Jan 2013
    Posts
    12
    Rep Power
    0

    Post Java Applet help

    Hey so im making an applet but it does really work her is my code

    main
    Java Code:
    import javax.swing.JApplet;
    import java.applet.Applet;
    
    public class Selvudvikling  extends JApplet{
    	
    	public static void main(String[] args) {
    		new GridLayour(); // Her starter jeg Gui'en
    	}
    }
    gui
    Java Code:
    import javax.swing.JFrame;  
    import javax.swing.JButton;  
    import javax.swing.JApplet;
    import java.applet.Applet;
    import java.awt.GridLayout;  
    import java.awt.event.ActionEvent;
    import java.awt.event.ActionListener;
    import java.io.File;
    import java.awt.*;
    import java.awt.event.*;
      
    public class GridLayour extends JApplet {
    {  
     final JApplet frame = new JApplet();  
     GridLayout layout=new GridLayout(4,1);  
     frame.setLayout(layout);  
      
     Button button1=new Button("Fysisk");
     button1.addActionListener(new ActionListener(){
    	 public void actionPerformed(ActionEvent e)
            {
    		 FileReader1.FileReader1();
    		
            }
        });
     
     Button button2=new Button("Psykisk");
     button2.addActionListener(new ActionListener(){
    	 public void actionPerformed(ActionEvent e)
            {
    		 FileReader2.FileReader2();
    		
            }
        });
     
     Button button3=new Button("Andet");
     button3.addActionListener(new ActionListener(){
    	 public void actionPerformed(ActionEvent e)
            {
    		 FileReader3.FileReader3();
    		
            }
        });
     
     Button button4=new Button("Q and A");  
      
     frame.add(button1);    
     frame.add(button2);  
     frame.add(button3);  
     frame.add(button4);   
     frame.setSize(400,400);  
     frame.setVisible(true);  
    }  
    }

    filereader
    Java Code:
    import java.io.*;
    
    class FileReader1 {
    
    	/**
    	 * @param object 
    	 * @param args
    	 */
    	public static String FileReader1(){
    		// TODO Auto-generated method stub
    	String str;
    		try{
    			  // Open the file that is the first 
    			  // command line parameter
    			  FileInputStream fstream = new FileInputStream("FileReader1.txt");
    
    			  // Get the object of DataInputStream
    			  DataInputStream in = new DataInputStream(fstream);
    			  
    			  BufferedReader br = new BufferedReader(new InputStreamReader(in));
    			  
    			  //Read File Line By Line
    			  
    			  while ((str = br.readLine()) != null)   {
    			  // Print the content on the console
    			  System.out.println (str);
    			  return str;
    			  }
    			  
    			  //Close the input stream
    			 // in.close();
    			  
    		  }catch (Exception e){//Catch exception if any
    			  System.err.println("Error: Her er vores egen fejlmeddelelse " + e.getMessage());
    			  return "der kom en esception"; 
    			  }
    		return "der er blevet læst noget, men heller ikke opstået en exception";
    	}
    
    }

  2. #2
    KevinWorkman's Avatar
    KevinWorkman is offline Crazy Cat Lady
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    4,017
    Rep Power
    10

    Default Re: Java Applet help

    Quote Originally Posted by MrSulfat View Post
    but it does really work her
    What exactly does that mean?
    How to Ask Questions the Smart Way
    Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!

  3. #3
    MrSulfat is offline Member
    Join Date
    Jan 2013
    Posts
    12
    Rep Power
    0

    Default Re: Java Applet help

    Oh sry, i meant: but it wouldn't work.

  4. #4
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

    Default Re: Java Applet help

    Quote Originally Posted by MrSulfat View Post
    Oh sry, i meant: but it wouldn't work.
    But "wouldn't work" tells us essentially nothing. How doesn't it work? Does it compile? If not, can you post the error messages? Does it run but throw an exception? If so can you post the exception message? Is there anything else you can tell us so that we can understand your problem?

  5. #5
    MrSulfat is offline Member
    Join Date
    Jan 2013
    Posts
    12
    Rep Power
    0

    Default Re: Java Applet help

    It will run an applet. but there is no bottoms in the applet.

  6. #6
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

    Default Re: Java Applet help

    Quote Originally Posted by MrSulfat View Post
    It will run an applet. but there is no bottoms in the applet.
    You need to read up on how to create JApplets because you're not doing it right. For one you need an init method, for another, you almost never create a new JApplet(...) object. Again, read the tutorials which Google can help you with. Note you've a class with a non-static initializer block and I'm not quite sure why you're doing this as it doesn't really make much sense to me.

Similar Threads

  1. Replies: 1
    Last Post: 06-08-2012, 08:11 AM
  2. Replies: 0
    Last Post: 04-26-2012, 12:50 PM
  3. Replies: 30
    Last Post: 08-26-2011, 10:05 PM
  4. Java Applet to Applet communication
    By jsman in forum Java Applets
    Replies: 3
    Last Post: 04-05-2011, 03:23 PM
  5. applet class inside java.applet.* or java.awt.*
    By Manish87 in forum Java Applets
    Replies: 1
    Last Post: 09-27-2010, 03:15 PM

Tags for this Thread

Posting Permissions

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