Home Answers Viewqa Java-Beginners Graphic interface java help

 
 


will smith
Graphic interface java help
1 Answer(s)      a year ago
Posted in : Java Beginners

A modified checkers program with class name Checkers using double buffering. Somehow the program must have two top squares and two bottom squares. There should be two checkers of different color. The two checkers always move in opposite directions. When a checker reaches the end of its path, it should start moving backwards in the opposite direction.

Somehow need to enhance the Checkers program above to respond to mouse clicks. The checkers must stop moving whenever the user clicks and holds down the mouse. Then start moving again whenever the mouse is released. Cannot figure this out at all, please help.

View Answers

April 26, 2012 at 12:41 PM


1)Checkers.java:

 import java.awt.Graphics;
    import java.awt.Color;
    import java.awt.Image;
    import java.awt.event.*;

    public class Checkers extends java.applet.Applet implements Runnable, MouseListener
    {

      Thread thread;
      int x;
      int y;
      Image image;
      Graphics graphics;

      public void init()
      {
        addMouseListener(this);
        x = 5;
        y = 100;
       image = createImage(this.size().width, this.size().height);
       graphics = image.getGraphics();
      }

      public void start()
      {
        if (thread == null);
         {
          thread = new Thread(this);
          thread.start();
        }
      }

      public void stop()
      {
        if(thread != null)
         {
          thread.stop();
          thread = null;
        }
      }

      public void run()
      {
        while (true)
         {
          while(x <= 105)
            {
            repaint();
            try { Thread.sleep(100); }
            catch (InterruptedException e) { }
              y-=4;
              x+=4;
          }

            while(x >= 5)
            {
            repaint();
            try { Thread.sleep(100); }
            catch (InterruptedException e) { }
              x-=4;
              y+=4;
          }
        }
      }

      public void update(Graphics g)
      {
         paint(g);
      }


      public void paint(Graphics g)
      {
        graphics.setColor(Color.black);
        graphics.fillRect(0,0,100,100);

         graphics.setColor(Color.black);
         graphics.fillRect(100,100,100,100);

        graphics.setColor(Color.gray);
        graphics.fillRect(100,0,100,100);
         graphics.setColor(Color.gray);
         graphics.fillRect(0,100,100,100);    

        graphics.setColor(Color.red);
        graphics.fillOval(x,5,90,90);

         graphics.setColor(Color.blue);
         graphics.fillOval(y,100,90,90);

        g.drawImage(image,0,0,this);
      }
      public void destroy()
      {
         graphics.dispose();
      }

      public void mousePressed (MouseEvent e)
       {
            this.stop(); 
        }
        public void mouseReleased (MouseEvent e)
       {
            this.start();
        }

      public void mouseClicked(MouseEvent arg0) {}
        public void mouseEntered(MouseEvent arg0) {}
        public void mouseExited(MouseEvent arg0) {}
    }

2)applet.html:

<HTML>
<BODY>
<APPLET CODE ="Checkers.class" WIDTH="800" HEIGHT="500"></APPLET>
</BODY>
</HTML>









Related Pages:
Graphic interface java help
Graphic interface java help  A modified checkers program with class name Checkers using double buffering. Somehow the program must have two top..., please help
Game and Graphic Books
Game and Graphic Books        .... If it isn't there, it can't be learned, and if it is there, it can't help... system is a software interface to graphics hardware. (The GL stands for Graphics
help
(); } } SFDV2103 â?? Java Programming Fall, 2012 Term Project...: â?¢ Modify the Person class, which will implement the comparable interface. â... on the percentage of cheating. SFDV2103 â?? Java Programming Fall, 2012 Term
interface.
interface.  Write short note on interface.   Please visit the following link: Java Interface
INTERFACE
INTERFACE  how interface support multiple inheritance in java
interface
interface  What is marker interface ?? what is its use in java programming?? is this us in programming ??Explain is implementation with code
interface
interface  what the use of interface?   An interface is one... variables.Any class can implement(inherit)the interface and make use of the methods(functions) and variables within it. In java, multiple inheritance
Interface
for Interface in java? and want to know why they used interface instead of multiple inheritance? Thanks in advance   An interface is one which has abstract... method it will take.It creates complexity.Therefore java uses Interface
interface
; Through interface, we can achieve the multiple inheritance. Java does...interface  What is the exact use of interface in real time scenario? some people says that interface provides multiple inheritance. Is it true
Abstract and Interface
Interface and Abstract Class 1)Main difference is methods of a Java interface... declared in a Java interface is by default final. An abstract class may contain non-final variables. 3)Members of a Java interface are public by default. A Java
interface
interface  sir/mam, pls tell me how interfaces reduce duplicasy in java.. atul
Java Graphical user interface
Java Graphical user interface  Hi, guys. I'm christina, need help... of your Java quiz GUI application are specified by the following program flow... of the screen when it starts. It provides an interface to register the student name
GUI Interface - Java Beginners
and multiplication. But use classes javax swing java awt java awt.event no other classes wil be used.I need it very urgent please help me for this  Hi...://www.roseindia.net/java/ Thanks
Interface and Abstract class
, visit the following link: http://www.roseindia.net/help/java/a/interface-vs... and Abstract Class 1)Main difference is methods of a Java interface are implicitly... methods that implements a default behavior. 2)Variables declared in a Java interface
ABSTRACTION AND INTERFACE - Java Interview Questions
the following links: http://www.roseindia.net/help/java/a/abstract-keyword.shtml...ABSTRACTION AND INTERFACE  When Use Abstract?When Use Interface ?I Want Explanations?plz help me  Hi Friend, When we do not want
can interface solve this problem in java
can interface solve this problem in java  I have a JDialog which... this calander class. can interface solve this problem. If yes then how. pls help me   Please visit the following link: http://www.roseindia.net
Sorting Router Interface in a list.
Sorting Router Interface in a list.  Hi All, I have list which contains router interface as GigabitEthernet 1/0, GigabitEthernet 1/1,GigabitEthernet..., GigabitEthernet 1/11 How can i achieve this type of sorting in java. It's really urgent
abstract class and interface - Java Beginners
://www.roseindia.net/help/java/a/interface-vs-abstract-class.shtml http...? when should we use an abstract class? when should we use interface instead of abstract class?   Hi friend, Abstract classes In java
Java interface
Java interface  What is the List interface
Java interface
Java interface  What modifiers may be used with an interface declaration
Java Interface
Java Interface  Can an Interface have an inner class?  Yes, interface can have inner class. for example- public interface gyan { static...("in interface"); }; public static void main(String args
Java interface
Java interface  What must a class do to implement an interface?  It must provide all of the methods in the interface and identify the interface in its implements clause
Abstract class and Interface - Java Magazine
Abstract class and Interface  Dear Sir, Please anyone help me........I wane exact difference between Abstract class and Interface.what... for more information, http://www.roseindia.net/java/master-java
Interface in java
Interface in java  An Interface method implemented in more than one different class with same method name. To avoid overriding of methods, we use ObjectReference for that class
help
help   how i can send a pitcture on url in java
graphical user interface - Java Beginners
graphical user interface  Help me write a code for this please Thank you. tried adjusting the previous one and got errors. Employee Details as Title Name (Text Field) Address (Text Area) Phone
help
help  pls help me to get the code of a java program a program to perform different shapes in a menu using javaapplet
java interface
java interface  Create a interface called student Define methods like get roll number Get name Get subject Create two classes Electronic student And history student Enter 5 students in the main class 2 of history and 3 elec
help
help  i need help with this code. write a java code for a method named addSevenToKthElement that takes an integer array, and an integer k as its arguments and returns the kth element plus 7. any help would be greatly
help
help  Hii.. I have to design one registration page in java that looks like REGISTER USERNAME (here i have to check whether username already exists... to the user) please tell me how could i design that. Please help me asap Thanks a lot
HOW TO DO WEBSITE INTERFACE FOR JAVA MODULE
HOW TO DO WEBSITE INTERFACE FOR JAVA MODULE  Hi , Greetings. I have created modules in java separately , example student registration , view... an interface ? any 3rd party software like frontpage can do or other method ? PLEASE
help
help  how can i query for a minimum value of of one of the column in my database through java   Use min to retrieve the minimum value from one column of database table. Suppose you have a table named emp where
help
this in java then try this: import java.util.*; class SquareNumber { public
help
Java application  public int remainder(int a, int b) { int answer = a % b; System.out.printf("%d % %d = ", a , b); return (answer); } and in my main, int answerRemain
Uses of abstract class & interface - Java Beginners
to java. I knew the basic concepts of interface and the abstract class. But i dont... my doubt Thank you  Hi Friend, Interface: Java does...: http://www.roseindia.net/help/java/a/java-abstract-class.shtml http
help
. Based on the above scenario, write a complete Java program. Your program should
logfile interface
logfile interface  How to create logfile interface for programs in java
null interface
null interface   what is the null interface and what is the use of it in real java project ?   Hi Friend, A null interface is an interface... interface informs Java that objects of the implementing class can be serialized
help - RMI
*; public interface Echo extends Remote { public String echo(String value) throws..., in this order: rmiregistry java EchoServer java EchoClient
Marker Interface,Java Marker Interface
Interface in Java       In this section we will learn about Interface and Marker Interfaces in Java... is also the interface's example. But in java programming language interface is nothing
marked interface
marked interface  how jvm work with marked interface?(that means how it will know its behaviour with out any methods)   Hi, Learn it at Market Interface in Java tutorial page. Thanks
Interface - Java Beginners
Interface in Core Java  What is Interface? How Can i Use Interface in Core Java
Markable Interface
Markable Interface  In Java can we create our own Markable Interface?? If yes then how, Please explain with example   Marker interface : In java language programming, interfaces with no methods are known as marker
Set interface
is the example of Set Interface in Java. import java.util.*; public class...Set interface  hello,, What is the Set interface?   hii, The Set interface provides methods for accessing the elements of a finite
Java cloneable interface
Java cloneable interface  What is cloneable interface
web interface
web interface  hii sir, i want to develop a project name web GU interface for oracle like 10g can anyone help me plz how to develop using jsp and servelets provide code for WOI
Java interface reference
Java interface reference  When can an object reference be cast to an interface reference
Java Interface
Java Interface In this section we will discuss about the interface in Java... interfaces. Interface in Java is created for referencing something to other. To create an interface in Java the keyword "interface" is used
Java Serializalble interface
Java Serializalble interface  What is the difference between Serializalble and Externalizable interface
interface - Java Beginners
interface  how to build interface in java programming language

Ask Questions?

If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.

Ask your questions, our development team will try to give answers to your questions.