Latest Tutorials| Questions and Answers|Ask Questions?|Site Map



Home Answers Viewqa Java-Beginners Graphic interface java help

Have Programming Question? Ask it here!
 
 
 


will smith
Graphic interface java help
1 Answer(s)      2 years and 3 months 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.


Advertisement
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 Tutorials/Questions & Answers:
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
Java interface
Java interface  What is the List interface
Advertisements
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
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
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
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
Interface in Java
Interface in Java Interface in java programming languages is a collection... oriented concept. Through interface only abstraction is achieved in java. Syntax...; Java. In an interface, only abstract method can be declared. Interface
Interface - Java Beginners
Interface in Core Java  What is Interface? How Can i Use Interface in Core Java
Java cloneable interface
Java cloneable interface  What is cloneable interface
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
interface - Java Beginners
interface  how to build interface in java programming language
Java Serializalble interface
Java Serializalble interface  What is the difference between Serializalble and Externalizable interface
interface variables - Java Beginners
interface variables  why interface variable is by default final? what was the necessisity to make it final? plz explain me with good java prog
interface - Java Beginners
interface  what is an interface? when we will we use an interface in java? what will achived using interface?  Hi friend, Interface : An interface is a named collection of method definitions (without
Java itrator interface
Java itrator interface  What is an Iterator interface?  An iterator over a collection. Iterator takes the place of Enumeration in the Java.... The iterator interface have these methods- boolean hasNext(); Object next
Interface - Java Interview Questions
Interface  Respected sir why we use Interface in java? because we... the interface's example. But in java programming language interface is nothing... a new interface, you are defining a new reference data type. You can use
interface - Java Beginners
interface  I need the complete program for Design of java interface for Stack ADT and implement the same using array and linked list in java. Kindly send it as soon as possible. SOme of your solutions are not accessible
Abstract class and interface in Java
Abstract class and interface in Java  What is the difference between abstract class and interfaces in Java?   Differences between an interface and an abstract class: At the same time multiple interfaces can
INTERFACE - Java Interview Questions
INTERFACE  Why Use Interface in Java?i want region ?plz post answer   Hi Friend, Interfaces form a contract between the class... the methods of the interface are implemented with the correct signature.Interfaces
Interface in Java
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
interface - Java Magazine
engineering in gujrat.and i dont know about actual useof interface in java and in all java technology so plz solve my question sir  Hi Friend, Please visit the following link: http://www.roseindia.net/tutorial/java
about interface - Java Beginners
of the given line Set si=new HashSet(); Problem is that Set is an interface and HashSet is a class... so how instantiation of interface is possible..or..what...://www.roseindia.net/java
Interface - Java Beginners
Interface  Dear Sir, Could you send me a java program for INTERFACE... java.lang.*; import java.io.*; import java.util.*; interface MyInterface { int...://www.roseindia.net/java/master-java/interface.shtml Thanks
interface - Java Beginners
Interface meaning in java  What is the meaning of Interface? and why we need to call
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
interface - Java Beginners
Interface definition language example  example of interface definition  If it is a Class --> Interface is implemented. A class may implement multiple interfaces.if it is an Interface --> Interface can be extended
interface.
interface.  Write short note on interface.   Please visit the following link: Java Interface
interface variables - Java Beginners
interface variables  why interface variables are final? explain me with good program example?? i knw why the variable is static but,i dont knw why it is final by default? thanks in advance
Interface - Java Beginners
Interface  Assignment: You are given the following interface: interface Stats { double getAverage(); //returns the average of scores... } implement the interface in a class called Grades. The program will read a series
JAVA INTERFACE - Java Interview Questions
JAVA INTERFACE  Can Any Interface will have inner classes... Whether an interface be final????  Hi friend, Yes, as for example, public interface TestInterface { // Inner class inside an interface
Interface in JAVA - Java Interview Questions
. To sort out this flaw java has provided Interface which supports the Multiple... on the Interface. http://www.roseindia.net/java/java-exception/create-interface.shtml...Interface in JAVA  How interface fulfills all th facilities which
Gui Interface - Java Beginners
Gui Interface  hi I have two seperate interfaces in the same projects . my question is how can I access this interface using a jbutton (i.e jbutton = next where next points to another interface addCourse.java) What would
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
INTERFACE  how interface support multiple inheritance in java
Interface in java with example
We are going to discuss about Interface in Java. Interface is blueprint... implement them. Java interface is nothing but is a empty collection... extending interface. Why use interface in java? We use itto achieve complete
Java-Generic Interface
Java-Generic Interface  Hi Friends, The current connector... and publish it to java program -Now we are getting request from other modules in our... replace C connector by java program which can receive xml messages and parse
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
Help With Java...
Help With Java...  Write a java program that can take a positive integer greater than 2 as input and write out the number of times one must repeatedly divide this number by 2 before getting a value less than 2
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
interface
interface  What is marker interface ?? what is its use in java programming?? is this us in programming ??Explain is implementation with code
java help!
java help!   I need help starting off a program I am trying to write for class. The class should contain a private instance variable to represent temperature in Degrees Celsius and it should have the following methods
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
help in java
help in java   Rational Numbers Rational numbers are numbers that can be represented as a fraction p / q where p is an integer number and q is a positive integer (q != 0). Design and implement a Java class RationalNumber
Marker Interface - Java Interview Questions
.  Hi friend, Marker interface : In java language programming... more information on Marker interface visit to : http://www.roseindia.net/java...Marker Interface   Hi Deepak, Marker interface means
problem on marker interface - Java Beginners
problem on marker interface  i want to know about marker interface... tagged or marker interface is used to just identify the class, in real time... module,this tag or marker interface is useful. *. In serialization also
help in java
help in java  Write an application that prompt the user to enter a number to use as an array size, and then attempt to declare an array using the entered size. Java generates a NegativeArraySizeException if wou attempt to create
Advertisements
 

 

 

DMCA.com