Results 1 to 7 of 7
  1. #1
    n_cruz21 is offline Member
    Join Date
    Oct 2010
    Posts
    3
    Rep Power
    0

    Unhappy 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

  2. #2
    pbrockway2 is offline Moderator
    Join Date
    Feb 2009
    Location
    New Zealand
    Posts
    4,565
    Rep Power
    12

    Default

    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.

  3. #3
    n_cruz21 is offline Member
    Join Date
    Oct 2010
    Posts
    3
    Rep Power
    0

    Default

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

  4. #4
    pbrockway2 is offline Moderator
    Join Date
    Feb 2009
    Location
    New Zealand
    Posts
    4,565
    Rep Power
    12

    Default

    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.

  5. #5
    n_cruz21 is offline Member
    Join Date
    Oct 2010
    Posts
    3
    Rep Power
    0

    Default

    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!

  6. #6
    mcurry is offline Member
    Join Date
    Feb 2012
    Posts
    2
    Rep Power
    0

    Default 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?

  7. #7
    DarrylBurke's Avatar
    DarrylBurke is offline Member
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,184
    Rep Power
    19

    Default Re: i'm new to java and having troubles making an ascii animation

    Quote Originally Posted by mcurry View Post
    Would it not be easier to put it into an array that it cycles through?
    No. And was it really necessary to wake a thread that's more than a year old to ask that? When you have a question, start a new thread -- they're free.

    Closing this.

    db
    If you're forever cleaning cobwebs, it's time to get rid of the spiders.

Similar Threads

  1. Java and PHP4 ASCII
    By cooper01 in forum New To Java
    Replies: 4
    Last Post: 06-01-2010, 02:38 PM
  2. Troubles,convert C/C++ Code to Java
    By cristianll in forum New To Java
    Replies: 1
    Last Post: 11-15-2009, 02:30 AM

Posting Permissions

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