shapes

shapes

hi pliz help me put a shape in this code such that when the answer is equal and right it shuld change the color of the background and puts a shape. pliz help its urgent

import java.awt.Dimension; import java.awt.FlowLayout; import java.awt.GridLayout; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.text.DecimalFormat; import java.text.NumberFormat; import java.util.Random; import javax.swing.JButton; import javax.swing.JFormattedTextField; import javax.swing.JFrame; import javax.swing.JLabel; import javax.swing.JOptionPane; import javax.swing.JPanel; import javax.swing.UIManager; import javax.swing.border.EmptyBorder; import java.awt.Color; import java.awt.Container;

//****************** public class MathsClass extends JFrame { private JPanel components; private JPanel buttonPanel; private JLabel number,square; private JFormattedTextField numberField; private JFormattedTextField squareField; private JButton okButton; private NumberFormat numberFormatter; private JPanel panel1; private JButton button; Random randomNumber=new Random(); int randomNO; int randomSquare;

//********************** //MathsClass constructor public MathsClass() {

    super("Mathematical Tutor");
    setLayout(new FlowLayout());//set frame layout
    setFormats();
    //its meant to set the background color of the frame
    Container winnie = getContentPane();
    winnie.setBackground(Color.blue);


    components=new JPanel(new GridLayout(2,3,0,3));
    components.setBorder(new EmptyBorder(20,20,20,20));
    components.setPreferredSize(new Dimension(350,100));

    buttonPanel=new JPanel();
    buttonPanel.setBorder(new EmptyBorder(20,0,0,10));//set size of the EmptyBorder
    number= new JLabel("Number:");
    square= new JLabel("Number Squared:");
    numberField=new JFormattedTextField();
    numberField.setEditable(false);//only gets input from the computer
    numberField.setValue((generateRandom()));
    squareField=new JFormattedTextField(numberFormatter);//put only integers in the textfield


    okButton=new JButton("Ok");

    okButton.addActionListener
        (
  //*******************************************************************         
        new ActionListener()
        {
               public void actionPerformed(ActionEvent evt)
            {
               int num=((Number)numberField.getValue()).intValue();
                           int input=((Number)squareField.getValue()).intValue();
                           //calculation of squares of the random numbers
                           randomSquare=(num*num);


                         if(input==(randomSquare))
                           {
                            //display the color of the OptionPane background
                               UIManager.put("OptionPane.background", Color.cyan);
                               JOptionPane.showMessageDialog(MathsClass.this,"Huraah, the answer is right",
                "The Square of the number.",JOptionPane.INFORMATION_MESSAGE );


                           }

                          else
                           {
                              //remove the background color
                               UIManager.put("OptionPane.background", "null");
                               //used to display the message
                               JOptionPane.showMessageDialog(MathsClass.this,"Sorry the answer is Wrong . "
                                       + "The right answer is:" + randomSquare,
                "The Square of the number.",JOptionPane.INFORMATION_MESSAGE );
                           }
                           numberField.setValue((generateRandom()));
                           // to clear automatically
                           squareField.setValue(null);

            }
        }
        );

    components.add(number);//add number to JFrame
    components.add(numberField);//add numberfield to JFrame
    components.add(square);//add square to JFrame
    components.add(squareField);//add squarefield to JFrame

     buttonPanel.add(okButton);// add the ok button to JFrame


    components.setBackground(Color.magenta);//set background color of the components
    buttonPanel.setBackground(Color.blue);//set background color of the frame
    winnie.add(components);//add components to JFrame
    winnie.add(buttonPanel);//add buttonPanel to JFrame


}

//********************* //to generate random numbers private int generateRandom() { //numbers between 1 and 10 randomNO=1+ randomNumber.nextInt(9); return randomNO; }

//setFormats constructor private void setFormats() {

    numberFormatter=(DecimalFormat)NumberFormat.getNumberInstance();
    numberFormatter.setParseIntegerOnly(true);//convert string into int values in the calculation
}

//*********************** //main program public static void main(String[] args) {

                      MathsClass mathsClass = new MathsClass();//create MathsClass

              mathsClass.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

              mathsClass.setSize(400,350);//set frame size
                      mathsClass.setResizable(false);//inability to minimize
              mathsClass.setVisible(true);//display frame


                    }
        }
View Answers









Related Tutorials/Questions & Answers:
display shapes
display shapes  Hi, I would like to see geometric shapes like square, triangle, circle, rectangle as my outputs. Also, those figures shouldn't overlap while they get displayed. Please help me
shapes
Advertisements
ModuleNotFoundError: No module named 'shapes'
ModuleNotFoundError: No module named 'shapes'  Hi, My Python... 'shapes' How to remove the ModuleNotFoundError: No module named 'shapes'... to install padas library. You can install shapes python with following command
java program of different shapes
java program of different shapes  pls help me to get the code of a java program of different shapes using menu
ModuleNotFoundError: No module named 'django-shapes'
ModuleNotFoundError: No module named 'django-shapes'  Hi, My... 'django-shapes' How to remove the ModuleNotFoundError: No module named 'django-shapes' error? Thanks   Hi, In your python
ModuleNotFoundError: No module named 'django-shapes'
ModuleNotFoundError: No module named 'django-shapes'  Hi, My... 'django-shapes' How to remove the ModuleNotFoundError: No module named 'django-shapes' error? Thanks   Hi, In your python
drawing shapes in applet - Applet
drawing shapes in applet  hi, i need a single applet prgm which draws cone,cube and square in circle.  Hi manju, This is cube example import java.awt.*; import java.awt.event.*; import java.awt.geom.*; import
Java Shapes Bouncing App
Java Shapes Bouncing App  hi guys, im trying to implement... JApplet and contains a panel where * shapes move around on the screen. Also... and reset all margins for all shapes public void
Write a Java applet to draw cylinder and pentagon shapes.
Write a Java applet to draw cylinder and pentagon shapes.  Write a Java applet to draw cylinder and pentagon shapes
Finding shapes in digital photos - java
Finding shapes in digital photos - java  Hello, I need some hints/tips regarding some project I'm doing. The project is about finding shapes... this information to separate the main different coloured shapes in the photo
ModuleNotFoundError: No module named 'adafruit-circuitpython-display-shapes'
ModuleNotFoundError: No module named 'adafruit-circuitpython-display-shapes...: ModuleNotFoundError: No module named 'adafruit-circuitpython-display-shapes' How...-shapes' error? Thanks   Hi, In your python environment you
Maven Repository/Dependency: io.circe | circe-shapes
Maven Repository/Dependency of Group ID io.circe and Artifact ID circe-shapes. Latest version of io.circe:circe-shapes dependencies. # Version Release Date You can read more at: Maven
Creating Shapes using Shape Groups
Creating Shapes using Shape Groups In this section, you will learn how to create shapes using Apache POI library. EXAMPLE import java.io.FileNotFoundException; import java.io.FileOutputStream; import java.io.IOException; import
Java - Drawing Shapes Example using color in java
Java - Drawing Shapes Example using color in java  ... will show you how to draw the different types of colorful shapes. This example show the different types of colorful shapes like line, circle and the rectangle. It also
shapes - Java Beginners
PHP GD polygon Shapes
Java - Drawing Shapes Example in java
Java - Drawing Shapes Example in java       Introduction Applet is a program to run... the different types of shapes like line, circle and rectangle
Show Intersection between the Area of two Shapes
Show Intersection between the Area of two Shapes  ... the intersection between the area of shapes in Graphics. Intersection means... by the package java.awt.geom.*. These classes provides the shapes rectangle and oval
Show the Exclusive OR between the Area of two Shapes
Show the Exclusive OR between the Area of two Shapes...*. These classes provides the shapes rectangle and oval respectively. Set... shows the ExclusiveOR between the two shapes: area1.exclusiveOr(area2
Drawing with Color in Java
how to draw colorful shapes in java swing. There are various colorful shapes... of methods to draw shapes and fill these with the appropriate color. In this tutorial we are going to create JFrame and then write the shapes on it. We are using
Drawing with Gradient Color in Java
gradient shapes. First of all you will know about the gradient color. The gradient... color in the shapes. ADS_TO_REPLACE_3 Syntax for GradientPaint
Show General Path
Show General Path       This section illustrates you how to create GeneralPath. We have used the class GeneralPath to create three different shapes. For this, we have create
Online Real-Time GPS Phone Tracking Service
Online Real-Time GPS Phone Tracking Service Online Real-Time GPS Phone Tracking Service is a useful service handy to track mobile phones and devices. They come in all forms and different shapes and sizes. Not only they are used
Types of GPS tracking devices
Types of GPS tracking devices GPS tracking devices come in all forms and different shapes and sizes. Whilst they are used on an advanced platform to track satellites and vehicles, they can also be used in households for tracking
Fashion Diamond Accessories
Fashion Diamond Accessories Fashion diamond accessories come in many different shapes and sizes, which means that you have to carefully choose the ones you use for a specific outfit. It is very important these days
Drop Box
Drop Box  program draw 2d shapes in java
Drop Box
Drop Box  program draw 2d shapes in java
openGL
openGL   hii, what is openGL ??   hello,ADS_TO_REPLACE_1 Opengl is used for creating basic shapes and provides these shapes with animation
rob
draw a series of shapes of increasing dimension  Write a java applet (File Name is SectionC.java) which will draw a series of shapes of increasing... and type of the shapes will be determined by the user. So the user will choose
rob
is SectionC.java) which will draw a series of shapes of increasing dimension as shown on the following diagram. [Hint: Use a loop]. The number and type of the shapes... or Square in JOPtionPane Question) and the number of shapes to be drawn. Based
rob
) which will draw a series of shapes of increasing dimension as shown on the following diagram. [Hint: Use a loop]. The number and type of the shapes... in JOPtionPane Question) and the number of shapes to be drawn. Based on the input
rob
is SectionC.java) which will draw a series of shapes of increasing dimension as shown on the following diagram. [Hint: Use a loop]. The number and type of the shapes... in JOPtionPane Question) and the number of shapes to be drawn. Based
rob
) which will draw a series of shapes of increasing dimension as shown on the following diagram. [Hint: Use a loop]. The number and type of the shapes... in JOPtionPane Question) and the number of shapes to be drawn. Based on the input
rob
will draw a series of shapes of increasing dimension as shown on the following diagram. [Hint: Use a loop]. The number and type of the shapes will be determined... in JOPtionPane Question) and the number of shapes to be drawn. Based on the input number
Fresher-Trainee
Fresher-Trainee  a java program to calculate the area of different shapes using Multilevel Inheritance
java
java  Design a simple applet that can draw shapes such as rectangles, circles, Lines and ovals. Set them to different colors
help
help  pls help me to get the code of a java program a program to perform different shapes in a menu using javaapplet
class - Java Beginners
) Abstract class Shapes has one abstract method-area() and a concrete method display(). Class Rectangle should implement the abstract class shapes Interface Shapes has abstract methods-area(),display(). Classes Rectangle and Triangle should
class - Java Beginners
) Abstract class Shapes has one abstract method-area() and a concrete method display(). Class Rectangle should implement the abstract class shapes Interface Shapes has abstract methods-area(),display(). Classes Rectangle and Triangle should
java sample program - Java Beginners
main(String[] args) { Shape shapes[] = new Shape[4]; shapes[0]= new Shape(); shapes[1] = new Square(); shapes[2] = new Rectangle(); shapes[3] = new Circle(); for(int i=0;i
java
the respective shapes. Use the Graphics class components to draw the shapes on a JPanel
Java map building - Development process
Java map building  Hello All I want to build a map for a road network from ESRI shapefiles. Up to now i have the code that can read the shapfiles like polyline, polygon, points etc fetch the coordinates from the shapes. Now
Java Bouncing Application
to create new shapes -Sorting function in array list The code is too large
how can i print the selected content of a frame
how can i print the selected content of a frame  hello sir, I am designing a bill calculate program. I want to print the bill in crystal form. I want to skip all the text fields shapes and all the button from the frame.. but all
coding shape
coding shape  i need to write a simple java program. the system must be in an applet and allows a user to choose whether to draw shapes such as circles, rectangles or lines on the screen. also, user can add circles by choosing
Structural Design Patterns
there are several sockets of different sizes, and shapes in a house. Due
java - Applet
java  1.An applet program to draw a line graph for y=2x+5.[for suitable values of x & y] 2. An applet program to draw following shapes (1)cone, (2)cube, (3)square inside a circle  Hi friend, this is cubic code
How to design a stone
: Choose "E7E7E7" color and Pen tool (P key) to make two shapes
What is Logo Design
shapes, colors, fonts, and images usually are different from others in a similar... of company. The images, shapes, typefaces and colors display the image of your
What is AWT in java
is used for represent the geometric shapes. Stroke allows the Graphics2D object and contains the shapes to outline

Ads