import javax.swing.* ;
import java.awt.* ;
import java.awt.event.* ;
import java.util.* ;
public class KanjiInterface extends JFrame {
JMenuBar menuBar ;
JMenu menuSession ;
JMenuItem subNewGame, subLoadGame ;
MyComponent graphArea ;
Color one = Color.blue ;
Color two = Color.blue ;
Color three = Color.blue ;
Color four = Color.blue ;
int firstx[]={275,325,325,275} ;
int firsty[]={100,100,175,175} ;
int secondx[]={150,450,450,150} ;
int secondy[]={180,180,230,230} ;
int thirdx[]={255,292,180,143} ;
int thirdy[]={263,300,412,375} ;
int fourthx[]={345,308,420,457} ;
int fourthy[]={263,300,412,375} ;
Polygon firstStroke = new Polygon(firstx,firsty,4) ;
Polygon secondStroke = new Polygon(secondx,secondy,4) ;
Polygon thirdStroke = new Polygon(thirdx,thirdy,4) ;
Polygon fourthStroke = new Polygon(fourthx,fourthy,4) ;
ArrayList<Integer> strokes = new ArrayList<Integer>() ;
int totalElements = strokes.size() ;
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 MyComponent() ;
graphArea.setBackground(Color.WHITE) ;
add(graphArea, BorderLayout.CENTER) ;
setVisible( true ) ;
//Adding listener
graphArea.addMouseListener(new MouseCatcher ()) ;
for(int index = 0 ; index < totalElements ; index++){
StrokeChecker() ;
}
}
class MyComponent extends JPanel{
public void paintComponent(Graphics g){
super.paintComponent(g) ;
g.setColor(one) ;
g.fillPolygon(firstStroke) ;
g.setColor(two) ;
g.fillPolygon(secondStroke) ;
g.setColor(three) ;
g.fillPolygon(thirdStroke) ;
g.setColor(four) ;
g.fillPolygon(fourthStroke) ;
}
}
public class MouseCatcher extends MouseAdapter {
public void mouseClicked(MouseEvent e)
{
int xpos = e.getX();
int ypos = e.getY();
if(firstStroke.contains(xpos,ypos)){
one = Color.red ;
strokes.add(1) ;
}
if(secondStroke.contains(xpos,ypos)){
two = Color.red ;
strokes.add(2) ;
}
if(thirdStroke.contains(xpos,ypos)){
three = Color.red ;
strokes.add(3) ;
}
if(fourthStroke.contains(xpos,ypos)){
four = Color.red ;
strokes.add(4) ;
}
repaint() ;
}
}
public void StrokeChecker(){
int x = strokes.get(0) ;
System.out.println("The first stroke is " + x) ;
}
}