I know some things about JApplet, but how do you make an applet that will let you upload files, and open, or at least download, files.
Also, how do you get it to paint in more than once color?
Welcome to the Java Programming Forums
The professional, friendly Java community. 21,500 members and growing!
The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.
>> REGISTER NOW TO START POSTING
Members have full access to the forums. Advertisements are removed for registered users.
I know some things about JApplet, but how do you make an applet that will let you upload files, and open, or at least download, files.
Also, how do you get it to paint in more than once color?
For file navigation to save or select, see How to Use File Choosers. For applets, doing so requires your applet be signed. See the following: Signed Applets - How to sign an applet (and get it to work)
Vague answers (or none at all) result from vague questions. I suggest you start another thread with this question, containing a bit more information and code describing the problem, what you have, and what you wish to accomplish.Also, how do you get it to paint in more than once color?
Last edited by copeg; August 28th, 2010 at 10:06 PM.
In applets you use paint instead of paintComponenet?
In Applets you can override paint(...)
In JApplets you can override paintComponent(...)
Better than either is to override paintComponent(..) in a JPanel or JComponent and add that (or set as contentPane) in a JApplet. That way, you can re-use your JPanel/JComponent by adding the same JPanel to a JFrame/JDIalog or by passing it as the message parameter to a JOptionPane.
db
^^ what Darryl said.
Build your GUI off of a JPanel/JComponent, then you can simply add it to your applet if you want to make an Applet/JApplet, or you can set it to the content pane of your JFrame if you want a stand-alone Java application.
I override a jpanel and add it to my JFrame. Thanks for the info.
I've seen them make an applet with shapes drawn in more than one color, but that used a switch statement and I'm not good at those, maybe I should have paid a bit more attention in class when that part was discussed. Anyway, if a break statement at line two will take it out of the switch structure even if a valid and true value was on line 3, do you use continue if you want it to check line 3 and so on?
Also, maybe I'm just a but are FileChoosers pretty complicated, i.e. something someone who's only been doing GUIs for less than a year's worth, should be fiddling with, or are they pretty easy to get it to read and write and upload stuff? I got it to write part of an object in another class thing but part of that object wasn't Serializable. Also, if I'm going to change components, like update the text in a text area, or have the saved layout start out with the last used background color setting, do I have to remove the old ones and bring in the updated ones? You can't add an Object to a JPanel. How do you put back in the object that was made from readObject() and writeObject()? However, if the said Object is also a Component then it can be added. Is there a way to make the writeObject() or readObject() value made by writing the Component and then reading the Object back in a reference variable of Component? Yeah I need a try and catch block to deal with the possibility of a Class Cast Exception, but is it doable?
JPanel panel = new JPanel(); Component comp = new Component(); panel.add(comp); JFileChooser chooser = new JFileChooser(JFileChooser.SAVE_DIALOG); File file = chooser.getSelectedFile(); OutputStream os = new OutputStream(file); ObjectOutputStream oos = new ObjectOutputStream(os); Object obj = oos.writeObject(comp); panel.remove(comp); JFileChooser chooser2 = new JFileChooser(JFileChooser.LOAD_DIALOG); File file2 = chooser2.getSelectedFile(); InputStream is = new InputStream(file2); ObjectInputStream ois = new ObjectInputStream(is); Object obj2 = ois.readObject(); Component c; try ( c = obj2; panel.add(c); } catch(ClassCastException cceRef) { System.out.println(cceRef.toString()); }
Also, it won't just be writing a Component itself, but actually a subclass like JTextArea, JButton, etc.
That might change what happens so I thought I should mention it.