Results 1 to 7 of 7
  1. #1
    mrguy is offline Member
    Join Date
    Jul 2012
    Posts
    27
    Rep Power
    0

    Default Graphics, Animation, and Interaction

    Hi guys,

    I am somewhat experienced in java graphics and all that other fun stuff that you can make cool little widgets and games. But a thought has crossed my mind and some have told me that my way of doing some of this isn't the way you should do it.

    So I am asking you to maybe provide example code that uses Graphics and has a timer in which the Graphics updates every frame and you can use mouse and keyboard. No flicker, accurate timer. ya know. Uses JFrame. I would be more then happy if you guys offer some working code examples.

    yea,
    Mr. guy
    Last edited by DarrylBurke; 07-22-2012 at 08:56 PM.

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

    Default Re: Graphics, Animation, and Interaction

    What exactly are you looking for and why? Your request doesn't make sense to me.

    For example:

    Quote Originally Posted by mrguy View Post
    I am somewhat experienced in java graphics and all that other fun stuff that you can make cool little widgets and games. But a thought has crossed my mind and some have told me that my way of doing some of this isn't the way you should do it.
    What exactly is "your way" of doing graphics? How can we tell if it's wrong if we have no idea what it is?

    So I am asking you to maybe provide example code that uses Graphics and has a timer in which the Graphics updates every frame and you can use mouse and keyboard. No flicker, accurate timer. ya know. Uses JFrame. I would be more then happy if you guys offer some working code examples.
    You're kind of asking us to re-write a general graphics tutorial without letting us know what exactly confuses you. Most of us would rather you read the tutorials that are already out there and then point out specific points that confuse you. This would be much more efficient for both you and us.

    Edit: as for examples, there are plenty decent ones that have been posted previously in this forum and in others, some created by me. Please feel free to explore, test and modify. Then if you need more help, show us what you've come up with code-wise and any specific problems or errors you might be having. In questions such as these, the onus of code creation really should be on you.
    Last edited by Fubarable; 07-22-2012 at 03:51 AM.

  3. #3
    mrguy is offline Member
    Join Date
    Jul 2012
    Posts
    27
    Rep Power
    0

    Default Re: Graphics, Animation, and Interaction

    Oh sorry. I forgot to say, how I had become experienced was from just picking up small things from tutorials and I figured if it works then I'm good to go. But in some cases I use things in the wrong context such as this:

    Java Code:
    import javax.swing.*;
    import java.awt.*;
    import java.awt.event.*;
    public class thing extends JFrame {
    	JPanel panel=new JPanel();
    	public thing(){
    		this.setTitle("Thing");
    		panel.setPreferredSize(new Dimension(400,500));
    		this.add(panel);
    		
    		this.addWindowListener(new WindowAdapter() {
    			public void windowActivated(WindowEvent e) {
    				paint();
    			}
    		});
    		
    		this.addWindowListener(new WindowAdapter() {
    			public void windowClosing(WindowEvent e) {System.exit(0);}
    		});
    		
    		this.pack();
    		this.setVisible(true);
    	}
    	public static void main(String[] args){
    		new thing();
    	}
    	public void paint(){
    		Graphics g = panel.getGraphics();
    		g.drawLine(50,50,100,100);
    	}
    }
    This here is just a small example of Graphics on a panel on a frame. Yea. It has problems but it works. Can some one provide something that works and does not have problems? And again if you happen to have an example with animation and interaction that would be much appreciated. thanks.

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

    Default Re: Graphics, Animation, and Interaction

    Quote Originally Posted by mrguy View Post
    Oh sorry. I forgot to say, how I had become experienced was from just picking up small things from tutorials and I figured if it works then I'm good to go. But in some cases I use things in the wrong context such as this:

    Java Code:
    public class thing extends JFrame {
    	JPanel panel=new JPanel();
    
    	//....
    	}
    
    	// ...
    
    	public void paint(){ // no... don't draw in the JFrame
    		Graphics g = panel.getGraphics(); // !!!!!!!!!!!!!!!!!!!!!!!! yikes! Never do this.
    		g.drawLine(50,50,100,100);
    	}
    }
    This here is just a small example of Graphics on a panel on a frame. Yea. It has problems but it works. Can some one provide something that works and does not have problems? And again if you happen to have an example with animation and interaction that would be much appreciated. thanks.
    Again, I have many examples of drawing in this forum, so please feel free to search and check them out. But first you *must* read two tutorials:

    Lesson: Performing Custom Painting (Basic Stuff)
    Painting in AWT and Swing (More Advanced Stuff)

  5. #5
    mrguy is offline Member
    Join Date
    Jul 2012
    Posts
    27
    Rep Power
    0

    Default Re: Graphics, Animation, and Interaction

    Alright thanks a lot . And um, how do you mark a forum as solved?

  6. #6
    DarrylBurke's Avatar
    DarrylBurke is online now Member
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,193
    Rep Power
    19

    Default Re: Graphics, Animation, and Interaction

    Quote Originally Posted by mrguy View Post
    how do you mark a forum as solved?
    A regression bug in the forum software has removed that option for ordinary members, so I've taken care of it for you.

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

  7. #7
    mrguy is offline Member
    Join Date
    Jul 2012
    Posts
    27
    Rep Power
    0

Similar Threads

  1. want help about ArrayList and interaction
    By chmo in forum New To Java
    Replies: 2
    Last Post: 11-03-2010, 01:45 PM
  2. GUI interaction
    By Glyph in forum New To Java
    Replies: 6
    Last Post: 10-19-2010, 07:43 PM
  3. Java interaction
    By satimis in forum New To Java
    Replies: 4
    Last Post: 06-30-2010, 05:14 PM
  4. Replies: 1
    Last Post: 06-15-2010, 11:57 PM
  5. program interaction possible?
    By Pierced1 in forum Advanced Java
    Replies: 3
    Last Post: 02-19-2009, 12:54 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
  •