Results 1 to 6 of 6
Thread: Java Applet help
- 02-21-2013, 07:29 PM #1
Member
- Join Date
- Jan 2013
- Posts
- 12
- Rep Power
- 0
Java Applet help
Hey so im making an applet but it does really work her is my code
main
guiJava 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 } }
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"; } }
- 02-21-2013, 07:34 PM #2
Re: Java Applet help
How to Ask Questions the Smart Way
Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!
- 02-21-2013, 07:42 PM #3
Member
- Join Date
- Jan 2013
- Posts
- 12
- Rep Power
- 0
Re: Java Applet help
Oh sry, i meant: but it wouldn't work.
-
Re: Java Applet help
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?
- 02-21-2013, 08:11 PM #5
Member
- Join Date
- Jan 2013
- Posts
- 12
- Rep Power
- 0
Re: Java Applet help
It will run an applet. but there is no bottoms in the applet.
-
Re: Java Applet help
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
-
IE8-9: Executing Java Script repeatedly causes Java Applet or JVM to crash
By JSuser in forum Java AppletsReplies: 1Last Post: 06-08-2012, 07:11 AM -
java applet JFileChooser: access denied (java.util.PropertyPermission user.dir read)
By jarah in forum Java AppletsReplies: 0Last Post: 04-26-2012, 11:50 AM -
Java Applet starts then the applet field goes light blue
By oki in forum Java AppletsReplies: 30Last Post: 08-26-2011, 09:05 PM -
Java Applet to Applet communication
By jsman in forum Java AppletsReplies: 3Last Post: 04-05-2011, 02:23 PM -
applet class inside java.applet.* or java.awt.*
By Manish87 in forum Java AppletsReplies: 1Last Post: 09-27-2010, 02:15 PM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks