Results 1 to 6 of 6
  1. #1
    DudeJericho is offline Member
    Join Date
    Apr 2011
    Location
    London
    Posts
    5
    Rep Power
    0

    Default My Chinese character project

    I'm having trouble figuring out on how about to do this project I chose to do. I want to create a program that basically teaches people about Kanji and their correct stroke order (they must draw the character in a certain way like from top to bottom for the first stroke, left to right for the second etc.). The user will first be presented with some pictures or something that shows them the correct stroke order and then they have to attempt it.

    I think I can figure out how to bring up those images to the user, but my real problem is how about to do the characters. The user would basically have to draw using the mouse starting from one set of co-ordinates (that would be pre-defined of course) to another set and the program has to know that the user passed through the correct co-ordinates thereby letting the user move on to the next stroke.

    I think I'm going way over my head with this since I don't have a great deal of Java experience (I took a course and am currently watching a lot of tutorial vids), so I'm thinking there might be an easier way like a connect the correct dots kind of system where the points the user clicks would act like the start/end points of the strokes.

    I haven't looked into it much yet but I came across a MouseMotionListener interface that seems to deal with something like what I want to do, but I have no clue how I would set the predefined co-ordinates using that.

    Does anyone have any advice on what I should be focusing on? Does anyone have any experience doing something similar? It seems I can't find anyone else doing this sort of thing..

    Thanks.:confused:

  2. #2
    bayan is offline Member
    Join Date
    Apr 2010
    Posts
    55
    Rep Power
    0

    Default

    Before you even attempt to write it in Java, you need to have in mind what algorithms you are going to use and write them down. Take into account trailing mistakes and how much error a user can make.

    Secondly please look up JPanels and JFrames before you start implementing listeners. Also this forum is for helping people with Java problems not teaching people new concepts. Please learn the concept and make an attempt to solve it and post here if you face any problems.

  3. #3
    ozzyman's Avatar
    ozzyman is offline Senior Member
    Join Date
    Mar 2011
    Location
    London, UK
    Posts
    797
    Blog Entries
    2
    Rep Power
    4

    Default

    you need to create your own custom Class for taking an image of a character, tracing its outline to vectors to make a path, and then pass the path vectors to another Class of your own which will create an order in which the strokes must be written by the user. When solving the user input, you'd have to have another Class just to allow variations in handwriting to match to the vectors.

  4. #4
    DudeJericho is offline Member
    Join Date
    Apr 2011
    Location
    London
    Posts
    5
    Rep Power
    0

    Default

    Thanks for the reply guys, sorry I didn't answer back sooner. Anyway due to the complexity of what I was attempting I decided to take a different route and opt for something more simpler. Basically I want to create the characters out of polygons, each polygon represents a "stroke" and the user needs to click them in the correct order. Upon clicking on them I would like the polygon to change colour, however I'm having trouble just getting the classes to interact with each other in the way I want.
    I've managed to get some Polgons on the screen and stuff, but I don't know how to use the mouseClicked method to change the colour of a polygon. Any help would be appreciated.

    Java Code:
    import javax.swing.*;
    
    public class KanjiGame {
    		public static void main(String args[]) {
    			new KanjiInterface ();
    		}
    }
    Java Code:
    import javax.swing.* ;
    import java.awt.* ;
    import java.awt.event.* ;
    
    public class KanjiInterface extends JFrame implements MouseListener {
    	
    	JMenuBar menuBar ;
    	JMenu menuSession ;
    	JMenuItem subNewGame, subLoadGame ;
    	KanjiPanel graphArea ;
    	//JPanel graphArea ;
    	//Polygon poly ;
    
    	
    	KanjiInterface(){
    		//Creates the window
    		super("Kanji Game") ;
    		setLocation( new Point(100, 100) ) ;
    		//this.getContentPane().setBackground( Color.white ) ;
    		setSize( 600, 600 ) ;
    		setResizable( true ) ;
    		
    		//Creates the Menu Bar along with sub-menus
    		menuBar = new JMenuBar() ;
    		menuSession = new JMenu("Session") ;
    		subNewGame = new JMenuItem("New Session") ;
    		subLoadGame = new JMenuItem("Load Session") ;
    		menuBar.add(menuSession) ;
    		menuSession.add( subNewGame ) ;
    		menuSession.add( subLoadGame ) ;
    		this.setJMenuBar(menuBar) ;
    		
    		//Create Panel for graphics
    		graphArea = new KanjiPanel() ;
    		graphArea.setBackground(Color.WHITE) ;
    	 	add(graphArea, BorderLayout.CENTER) ;
    	 	setVisible( true ) ;
    	 	
    	 	//Adding mouseListener to panel
    	 	graphArea.addMouseListener(this) ;
    		}
    	public void mouseClicked(MouseEvent e)
    	{
    		graphArea.paintComponent(setColor(Color.BLACK)) ;
    	}
    	public void mouseEntered(MouseEvent e)
    	{
    		
    	}
    	public void mouseExited(MouseEvent e)
    	{
    		
    	}
    	public void mousePressed(MouseEvent e)
    	{
    		
    	}
    	public void mouseReleased(MouseEvent e)
    	{
    		
    	}
    	/*private class MouseCatcher extends MouseAdapter{
    		public void mouseClicked(MouseEvent event){
    			
    	   }
    	}
    */
    }
    Java Code:
    import javax.swing.* ;
    import java.awt.* ;
    import java.awt.event.* ;
    
    
    public class KanjiPanel extends JPanel {
    	
    	public KanjiPanel(){
    		
    	}
    
    	public void paintComponent(Graphics g){
    		super.paintComponent(g) ;
    		Polygon poly = new Polygon() ;
    		Polygon poly2 = new Polygon() ;
    		Polygon poly3 = new Polygon() ;
    		g.setColor(Color.RED) ;
    		poly.addPoint(100,100) ;
    	    poly.addPoint(150,150) ;
    	    poly.addPoint(50,150) ;
    	    g.fillPolygon(poly) ;
    		//g.fillRect(25, 25, 100, 30) ;
    	    
    	    g.setColor(Color.blue) ;
    	    poly2.addPoint(200, 50);
    	    poly2.addPoint(300, 50);
    	    poly2.addPoint(300, 100);
    	    poly2.addPoint(200, 100);
    	    g.fillPolygon(poly2);
    	    
    	    g.setColor(Color.blue) ;
    	    poly3.addPoint(200, 150);
    	    poly3.addPoint(300, 150);
    	    poly3.addPoint(300, 200);
    	    poly3.addPoint(200, 200);
    	    g.fillPolygon(poly3);
    	}
    }
    I'm getting an error "The method setColor(Color) is undefined for the type KanjiInterface" which is annoying since I'm trying to call the method via an object of type KanjiPanel which has the method. I've tried a number of things but all I get is errors..

  5. #5
    j2me64's Avatar
    j2me64 is offline Senior Member
    Join Date
    Sep 2009
    Location
    Zurich, Switzerland
    Posts
    962
    Rep Power
    5

    Default

    Quote Originally Posted by DudeJericho View Post
    I'm getting an error "The method setColor(Color) is undefined for the type KanjiInterface" which is annoying since I'm trying to call the method via an object of type KanjiPanel which has the method. I've tried a number of things but all I get is errors..

    when you call a method without specifing a class then java search the method in the current object and because the call is made in this interace KanjiInterface java is looking in the interface. but there is no method named setColor in the interface. question: which component do you want to set the color?

  6. #6
    DudeJericho is offline Member
    Join Date
    Apr 2011
    Location
    London
    Posts
    5
    Rep Power
    0

    Default

    I want the paintComponent of KanjiPanel to set the colour of the polygon.. I think. I thought that using "." for graphArea would mean that it is refering to the method paintComponent of KanjiPanel since thats what graphArea is an object of and that I wouldn't need to specify the class.

Similar Threads

  1. Replies: 4
    Last Post: 02-01-2010, 11:13 AM
  2. Help with DND Character Creator project
    By legendofyams in forum New To Java
    Replies: 3
    Last Post: 12-08-2009, 04:26 PM
  3. Replies: 0
    Last Post: 04-19-2009, 06:38 PM
  4. this looks chinese to me
    By xgi1008 in forum New To Java
    Replies: 18
    Last Post: 10-05-2008, 07:03 PM
  5. reading text character by character
    By bugger in forum New To Java
    Replies: 2
    Last Post: 11-09-2007, 08:54 PM

Posting Permissions

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