Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

This is Java programing. Add the programing to show the random letter of fruit on J panel . You need to print whether the answer

This is Java programing. Add the programing to show the random letter of fruit on J panel . You need to print whether the answer is collect or not. The question is like R G E N A O, Then the answer is Orange. and Add the programing to show the time from the question show to a user answer.

This is Basic program.

import java.awt.*;

import java.awt.event.*;

import java.util.*;

import java.util.Timer;

import javax.swing.*;

import java.io.File;

import java.io.IOException;

import java.util.List;

class words{

String word; // single chracter

int x;

int y;

int r;

int g;

int b;

int dx;

int dy;

}

public class HelloWorld {

public static void main(String[] args) {

new myframe();// creating main jframe instance

}

}

class myframe extends JFrame

{

Container c;

JPanel panel;

JButton addbutton, startbutton;

JLabel catagory, ballsize;

JTextField guess;

JComboBox cb;

buttonListener handle;

myDrawboard myboard;

JFrame mainFrame;

public myframe()

{

super("Your title");

c = getContentPane();

guess = new JTextField(7);

guess.setFont(new Font("SansSerif", Font.BOLD, 50));

guess.setText("");

guess.addActionListener(new ActionListener(){

Random rnd = new Random();

public void actionPerformed(ActionEvent e){

//enter-key pressed

myboard.addChar(cb.getSelectedItem().toString());

// checkAnswer();

guess.setText("");

}});

catagory = new JLabel("Catagory");

startbutton = new JButton("Start");

startbutton.setFont(new Font("SansSerif", Font.BOLD, 30));

startbutton.setPreferredSize(new Dimension(120, 60));

cb = new JComboBox();

cb.addItem("Fruit");

handle = new buttonListener();

startbutton.addActionListener(handle);

panel = new JPanel();

panel.add(guess);

panel.add(catagory);

panel.add(cb);

panel.add(startbutton);

myboard = new myDrawboard();

c.add(myboard.panel, BorderLayout.CENTER);

c.add(panel, BorderLayout.SOUTH);

setSize(800, 600);

setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

setVisible(true);

// update screen (refresh)

Timer timer = new Timer();

timer.schedule(new myTimer(), 0, 16);

myboard.addWords();

}

class myTimer extends TimerTask

{

@Override

public void run() {

repaint();

}

}

class buttonListener implements ActionListener {

public void actionPerformed(ActionEvent action)

{

if (action.getSource() == startbutton)

{

if (startbutton.getText().equals("Start")) {

startbutton.setText("End"); }

else

startbutton.setText("Start");

}

}

}

}

class myDrawboard

{

private static int count = 0;

Graphics2D g2;

MyPanel panel = new MyPanel();

public void addChar(String word)

{

panel.addChar(word);

}

public void addWords()

{

panel.addWords();

}

}

class MyPanel extends JPanel {

ArrayList myFruit = new ArrayList();

ArrayList myColor = new ArrayList();

ArrayList myBody = new ArrayList();

ArrayList myQuestion = new ArrayList();

// List myQuestion = new Arrays.asList();

public MyPanel()

{

setBackground(Color.BLACK);

}

public void addWords(){

myFruit.add("APPLE");

myFruit.add("BANANA");

myFruit.add("GRAPE");

myFruit.add("ORANGE");

myFruit.add("MANGO");

myFruit.add("BLUEBERRY");

myFruit.add("KIWI");

myFruit.add("PEACH");

myFruit.add("PAPAYA");

myFruit.add("RASBERRY");

myFruit.add("LEMON");

}

public void addChar(String catagory){

// ArrayList myQuestion = new ArrayList();

myQuestion.clear();

Random rnd = new Random();

int index;

String answer="";

switch (catagory) {

case "Fruit":

index= rnd.nextInt(myFruit.size());

answer = myFruit.get(index);

break;

}

List letter = Arrays.asList(answer);

for (int i=0; i

myQuestion.add(letter.get(i));

}

}

public void paintComponent(Graphics g)

{

Graphics2D g2 = (Graphics2D) g;

g2.setColor(Color.BLACK);

g2.fillRect(0,0,getWidth(), getHeight());

int x=150;

int y=150;

for (int i = 0; i < myQuestion.size(); i++)

{

g2.setColor(Color.BLUE);

g2.setFont(new Font("SansSerif", Font.BOLD, 90));

g2.drawString(myQuestion.get(i),x,y);

}

}

}

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Students also viewed these Databases questions

Question

How should a committee decide which termination method to use?

Answered: 1 week ago

Question

What is the Definition for Third Normal Form?

Answered: 1 week ago

Question

Provide two examples of a One-To-Many relationship.

Answered: 1 week ago