Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

JAVA I need this program to display the coorelated image when the right hand whatsup button is clicked only after the button is pressed will

JAVA

I need this program to display the coorelated image when the right hand whatsup button is clicked only after the button is pressed will the image be displayed

I have three images called reading.jpg, talking.jpg, and driving.jpg.

here is my code so far:

app6.java

public class app6 { public static void main(String args[]) { myJFrame6 mjf = new myJFrame6(); } }

//...............................................//

myJButton.java

import java.awt.*; import javax.swing.*; public class myJButton extends JButton { public myJButton(String text) { super(text); setBackground(Color.red); setOpaque(true); } }

myJFrame6.java

import java.awt.*; import javax.swing.*; import java.awt.event.*; public class myJFrame6 extends JFrame { myJPanel6 p6; public myJFrame6 () { super ("My First Frame");

p6 = new myJPanel6();

getContentPane().setLayout(new BorderLayout()); getContentPane().add(p6, "Center");

setDefaultCloseOperation(EXIT_ON_CLOSE); setSize (550, 400); setVisible(true); }

}

//......................//

myJPanel6.java

package app6;

import java.awt.*; import javax.swing.*; import java.awt.event.*; import java.awt.image.BufferedImage; import java.io.File; import java.io.IOException; import javax.imageio.ImageIO; public class myJPanel6 extends JPanel { myJButton b1,b2; public myJPanel6() throws IOException { setLayout(new GridLayout(1,3)); student st1 = new student("John", "Smith", 20); b1 = new myJButton(st1.getName()); add(b1); String k=st1.WhatIsUp(); b2 = new myJButton(k); add(b2); JLabel label1 = new JLabel(); add(label1); if(k.equals("reading")) { BufferedImage myPicture = ImageIO.read(new File("reading.jpg")); label1.setIcon(new ImageIcon(myPicture)); } else if(k.equals("talking")) { BufferedImage myPicture = ImageIO.read(new File("talking.jpg")); label1.setIcon(new ImageIcon(myPicture)); } else if(k.equals("driving")) { BufferedImage myPicture = ImageIO.read(new File("driving.jpg")); label1.setIcon(new ImageIcon(myPicture)); } } }

//.....................//

student.java

class student {

String firstName; String lastName; int age; String status;

public student(String a, String b, int c) { firstName = a; lastName = b; age = c; if(age<=25) status = "Traditional"; else status = "Non-Traditional"; }

String getName() { return("NAME = "+firstName+ " "+lastName + ", Age = "+age+", Status = "+status); } int getAge() { return age; } String getStatus() { return status; } String WhatIsUp() { String b = "dunno"; double r = Math.random(); int myNumber = (int)(r*3f); if (myNumber == 0) b = "reading"; if (myNumber == 1) b = "talking"; if (myNumber == 2) b = "Driving"; return b; }

}

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

Recommended Textbook for

Database Driven Web Sites

Authors: Joline Morrison, Mike Morrison

2nd Edition

? 061906448X, 978-0619064488

More Books

Students also viewed these Databases questions

Question

What are Measures in OLAP Cubes?

Answered: 1 week ago

Question

How do OLAP Databases provide for Drilling Down into data?

Answered: 1 week ago

Question

How are OLAP Cubes different from Production Relational Databases?

Answered: 1 week ago