Results 1 to 7 of 7
- 10-26-2010, 10:31 PM #1
Member
- Join Date
- Oct 2010
- Posts
- 3
- Rep Power
- 0
i'm new to java and having troubles making an ascii animation
first semester of java and we just kind of hopped into it without learning syntax or anything so i'm kind of lost...and i need to make a asciianimation that will save and load my animations frame by frame...which is controlled by a GUI button...umm any tips would be very appreciated...
Java Code:import java.awt.*; import javax.swing.*; import java.awt.event.*; public class GUIDemo extends JFrame implements ActionListener{ JLabel lblOutput = new JLabel(); JPanel pnlControl = new JPanel(); JButton btnPrev = new JButton("<=="); JButton btnNext = new JButton("==>"); JLabel lblCounter = new JLabel("0"); JTextArea myText = new JTextArea(); JScrollPane scrollPane = new JScrollPane(myText); private int count = 0; public static void main(String[] args) { new GUIDemo(); }// end main public GUIDemo(){ super("GUI Demo"); //set up main layout this.setLayout(new BorderLayout()); this.add(myText, BorderLayout.CENTER); this.add(pnlControl, BorderLayout.SOUTH); //set up the panel pnlControl.setLayout(new FlowLayout()); pnlControl.add(btnPrev); pnlControl.add(lblCounter); pnlControl.add(btnNext); //register action listeners btnPrev.addActionListener(this); btnNext.addActionListener(this); this.setSize(200,200); this.setVisible(true); this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); }//end constructor public void actionPerformed(ActionEvent e){ if(e.getSource() == btnPrev){ //lblOutput.setText("Next"); count--; lblCounter.setText("" + count); }//end if for btnPrev if(e.getSource() == btnNext){ //lblOutput.setText("Next"); count++; lblCounter.setText("" + count); }//end if for btnNext }//end actionPerformed }//end public class GUIDemo
- 10-26-2010, 11:42 PM #2
Moderator
- Join Date
- Feb 2009
- Location
- New Zealand
- Posts
- 4,545
- Rep Power
- 11
Does this compile? If there is some message that you can't understand copy and post the whole message.
At runtime does the program have some behaviour you can't understand? If so, say what you were expecting to happen as well as the actual behaviour.
-----
It's all about understanding. But I'm sure you realise that and aren't actually expecting anyone to actually write your code for you!
But if you're stuck on some point (like how to read and write files, or how to represent frames of the animations in code) it will help if you're specific.
- 10-27-2010, 01:30 AM #3
Member
- Join Date
- Oct 2010
- Posts
- 3
- Rep Power
- 0
well it compiles but it is basically just a text window with buttons going previous and next that has a counter in between them...but yah you got it i'm having a problem with reading and writing the files...like i want to be able to write something on the current TextArea...then click next/prev and have a blank TextArea which i figured out how to do...and be able to write stuff on that...but then be able to go back to any previous frames and still have what i wrote on there earlier...
i'm not trying to get someone to write my code for me...but like i said my class just went from C++ to java and 90% of the class is java users...while i came from a C background...and there wasn't really anything said about syntax or any sort of functions...i understand that there are a billion inheritable functions i can use...but geez lol i just want to be able to save some text and get it when i go back to the frame...
- 10-27-2010, 02:35 AM #4
Moderator
- Join Date
- Feb 2009
- Location
- New Zealand
- Posts
- 4,545
- Rep Power
- 11
i just want to be able to save some text and get it when i go back to the frame
You are right there are a lot of methods available. A couple that are easy to miss for JTextArea are write() and read(). They are inherited from JTextArea's parent class.
The API documentation linked to above is *very* useful. Also Oracle's Tutorial.
In particular the read() and write() methods work with component's contents and an instance of Reader and Writer respectively. You will find the section on Character Streams very useful.
- 10-27-2010, 03:09 AM #5
Member
- Join Date
- Oct 2010
- Posts
- 3
- Rep Power
- 0
okay cool! i will dabble around with these and see if i can come up with the solution! it just bugs me that my professor would kind of just throw the few students in his class who haven't had any background in what is suppose to be an intro java class without going over any syntax or functionality or anything! but i really appreciate your help!
- 02-13-2012, 09:41 PM #6
Member
- Join Date
- Feb 2012
- Posts
- 2
- Rep Power
- 0
Re: i'm new to java and having troubles making an ascii animation
Would it not be easier to put it into an array that it cycles through?
- 02-13-2012, 09:57 PM #7
Re: i'm new to java and having troubles making an ascii animation
Why do they call it rush hour when nothing moves? - Robin Williams
Similar Threads
-
Java and PHP4 ASCII
By cooper01 in forum New To JavaReplies: 4Last Post: 06-01-2010, 02:38 PM -
Troubles,convert C/C++ Code to Java
By cristianll in forum New To JavaReplies: 1Last Post: 11-15-2009, 02:30 AM


LinkBack URL
About LinkBacks


Bookmarks