Home Answers Viewqa Swing-AWT please give me a java program for the following question

 
 


adithya
please give me a java program for the following question
2 Answer(s)      8 months ago
Posted in : Swing AWT

Write a java program that displays multiple frames : Step 1: Design a frame with three buttons: ?Fruit?, ?Bird? and ?Animal? Step 2: On clicking ?Fruit? button display another frame that shows a picture of a fruit of your interest. On clicking ?Bird? button display another frame that shows a picture of a bird of your interest. On clicking ?Animal? button display another frame that shows a picture of a animal of your interest. Have icons for your buttons

View Answers

September 17, 2012 at 1:40 PM


Here is an example that displays three buttons and display another frame when they are clicked.

import java.awt.*;
import javax.swing.*;
import java.awt.event.*;

public class MultipleFrame{

public static void main(String[] args){
JFrame f = new JFrame("");
f.setLayout(new FlowLayout());
JButton button1=new JButton("Fruit");
Icon icon1 = new ImageIcon("c:/fruit.png");
JButton button2=new JButton("Bird");
Icon icon2 = new ImageIcon("c:/bird.png");
JButton button3=new JButton("Animal");
Icon icon3 = new ImageIcon("c:/animal.png");
button1.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e){
 JFrame f1=new JFrame("Mango");
 Icon icon = new ImageIcon("c:/mango.jpg");
 JLabel lab=new JLabel();
 lab.setIcon(icon);
 f1.add(lab);
 f1.setVisible(true);
 f1.setSize(300,300);
 }
});
button2.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e){
 JFrame f1=new JFrame("Peacock");
 Icon icon = new ImageIcon("c:/peacock.jpg");
 JLabel lab=new JLabel();
 lab.setIcon(icon);
 f1.add(lab);
 f1.setVisible(true);
 f1.setSize(500,300);
 }
});
button3.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e){
 JFrame f1=new JFrame("Giraffe");
 Icon icon = new ImageIcon("c:/giraffe.jpg");
 JLabel lab=new JLabel();
 lab.setIcon(icon);
 f1.add(lab);
 f1.setVisible(true);
 f1.setSize(300,300);
 }
});
f.add(button1);
f.add(button2);
f.add(button3);

f.setSize(300,150);
f.setVisible(true);
f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
}

September 17, 2012 at 5:14 PM


In the previous code, we forget to add an icon to button. So we are sending the updated code.

import java.awt.*;
import javax.swing.*;
import java.awt.event.*;

public class MultipleFrame{

public static void main(String[] args){
JFrame f = new JFrame("");
f.setLayout(new FlowLayout());
JButton button1=new JButton("Fruit");
Icon icon1 = new ImageIcon("c:/fruit.png");
button1.setIcon(icon1);
JButton button2=new JButton("Bird");
Icon icon2 = new ImageIcon("c:/bird.png");
button2.setIcon(icon2);
JButton button3=new JButton("Animal");
Icon icon3 = new ImageIcon("c:/animal.png");
button3.setIcon(icon3);
button1.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e){
 JFrame f1=new JFrame("Mango");
 Icon icon = new ImageIcon("c:/mango.jpg");
 JLabel lab=new JLabel();
 lab.setIcon(icon);
 f1.add(lab);
 f1.setVisible(true);
 f1.setSize(300,300);
 }
});
button2.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e){
 JFrame f1=new JFrame("Peacock");
 Icon icon = new ImageIcon("c:/peacock.jpg");
 JLabel lab=new JLabel();
 lab.setIcon(icon);
 f1.add(lab);
 f1.setVisible(true);
 f1.setSize(500,300);
 }
});
button3.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e){
 JFrame f1=new JFrame("Giraffe");
 Icon icon = new ImageIcon("c:/giraffe.jpg");
 JLabel lab=new JLabel();
 lab.setIcon(icon);
 f1.add(lab);
 f1.setVisible(true);
 f1.setSize(300,300);
 }
});
f.add(button1);
f.add(button2);
f.add(button3);

f.setSize(300,150);
f.setVisible(true);
f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
}









Related Pages:
please give me a java program for the following question
please give me a java program for the following question  Write a java program that displays multiple frames : Step 1: Design a frame with three buttons: ?Fruit?, ?Bird? and ?Animal? Step 2: On clicking ?Fruit? button
hi.. please give me a java coding for the following question
hi.. please give me a java coding for the following question  Write a program that displays the following table (note that 1 mile is 1.609 kilometers). Miles Kilometers
hi.. please give me a java coding for the following question
hi.. please give me a java coding for the following question  Write a program that prompts the user to enter the number of students and each studentâ??s name and score, and finally displays the name of the students
hi.. please give me a java coding for the following question
hi.. please give me a java coding for the following question  Write a program that reads in investment amount, annual interest rate, and number of years, and displays the future investment value using the following formula
hi.. please give me a java coding for the following question
hi.. please give me a java coding for the following question  Suppose that the tuition for a university is RM10,000 this year and increases 5% every year. Write a program that computes the tuition in ten years and the total cost
hi.. please give me a java coding for the following question
hi.. please give me a java coding for the following question  Write a class that contains the following two methods: /* converts from inches...) The formula for the conversion is: inches = 2.54 * centimeters Write a program
hi.. please give me a java coding for the following question
hi.. please give me a java coding for the following question  Body Mass Index(BMI) is a measure of health on weight. It can be calculated by taking... a program that prompts the user to enter a weight in pounds and height in inches
please give me an idea to develop a program for this question?
please give me an idea to develop a program for this question?  How to enter a text or number from keyboard without using InputStreamReader method in java
hi.. please give me a java coding for the following question
hi.. please give me a java coding for the following question  Write a function called ChangeToNext that take in an uppercase character parameter ch. The function returns the next uppercase character if ch is between 'A' and 'Y
hi... pls give me the example of java coding fo following question
hi... pls give me the example of java coding fo following question  Write a java program that reads the following information and prints a payroll... withholding rate(e.g: 9%) The program should calculates the gross pay, total
hi... pls give me the example of java coding for following question
hi... pls give me the example of java coding for following question   Write a program that computes loan payments. The loan can be a car loan, a student loan, or a home mortgage loan. The program lets the user enter the interest
hi... pls give me the example of java coding fo following question
hi... pls give me the example of java coding fo following question  example java coding that reads in the radius and length of cylinder and computes volume. formula: Area = radius * radius * PI Volume = area * length
Please give me coding for this..
Please give me coding for this..  Write an application that inputs... spaces each.For Example.if the user types the number 42339,the program should print... happens when you execute the program and type a number with more than five digits
please help me to give code - Java Beginners
please help me to give code  Write a program that prints an n-level stair case made of text. The user should choose the text character..., http://www.roseindia.net/java
please help me to give code - Java Beginners
please help me to give code  Write a program that uses loops to generate an n x n times table. The program should get n from the user. As a model here is a 4 x4 version: | 1 2 3 4
please help me to give code - Java Beginners
please help me to give code  Write a program that reads a file named... John von Neumann Donald Knuth Charles Babbage Grace Hopper your program should...(); } } } ------------------------------- read for more information, http://www.roseindia.net/java/beginners/read
Plz give me code for this question
Plz give me code for this question  Program to find depth of the file in a directory and list all files those are having more number of parent directories
hello sir, please give me answer - Java Beginners
hello sir, please give me answer  Write a program in Java that calculates the sum of digits of an input number, prints... ways in java? so , sir please tell me full solution of this program   Here is your complete
why and where we use setter and getter methods in java, please give me one example program.....
why and where we use setter and getter methods in java, please give me one example program.....  why and where we use setter and getter methods in java, please give me one example program
Please give me the code for the below problem - Java Interview Questions
Please give me the code for the below problem  PROBLEM : SALES TAXES Basic sales tax is applicable at a rate of 10% on all goods, except books... Vidya  Hi Friend, Try the following code: import java.util.
please help me to give code - Java Beginners
please help me to give code  Write a function with a signature cheerlead(word) that prints a typical cheer as follows. The word robot: Gimme an R Gimme an O Gimme a B Gimme an O Gimme a T What did you give me? ROBOT
please help me to give code - Java Beginners
please help me to give code  Write a function, sliding(word, num)that behaves as follows. It should print out each slice of the original word having length num, aligned vertically as shown below. A call to sliding(examples, 4
please help me to answers this question about C++.....huuhuhuhu
please help me to answers this question about C++.....huuhuhuhu  1) Write a full program for the bubble sort algorithm. User is required to enter... program fragments: a. Give an analysis of the running time (Big-Oh) b
please help me to answers this question about C++.....huuhuhuhu
please help me to answers this question about C++.....huuhuhuhu  1) Write a full program for the bubble sort algorithm. User is required to enter... program fragments: a. Give an analysis of the running time (Big-Oh) b
Please give me the answer.
"int a=08 or 09" its giving compile time error why   "int a=08 or 09" its giving compile time error why ? can any one give me the answer of this please
please help me for this program - Java Beginners
please help me for this program   Write a program that asks the user for a starting value and an ending value and then writes all the integers... 11 12 13 14   Hi Friend, Try the following code: import
Please find me a solution that
Please find me a solution that   Write a java program that calculates the area of rectangular, square, triangular, and circle. Your program must have the following: Two classes named "Area" and "AreaTest". Class "Area
question
question  Sir, how to write the following code in jsp , avoid swing components , please give me the following code in another method , iwant... EditorPaneFrame() { setTitle("Java Web Browser"); setSize
question
question   sir plz tell me what should i give in title box. just i want java program for the question typed in this area
question
question   sir plz tell me what should i give in title box. just i want java program for the question typed in this area
Give me some java Forum like Rose India.net
Give me some java Forum like Rose India.net  Friends... Please suggest some forum like RoseIndia.net where we can ask question like here. Thanks
Give me some java Forum like Rose India.net
Give me some java Forum like Rose India.net  Friends... Please suggest some forum like RoseIndia.net where we can ask question like here. Thanks
question
question  please give me a simple program using bean + jsp + mysql
Question
Question  Sir, give me a java program to count the number of tokens , given a string and a seperator
question
question  Good Morning Sir, Please give me Java source code for Peer-to-Peer Streaming
question
question  Please give me a code for search engine using java and mysql
question
question  Sir, Please give me a source code for client server socket programing in java
Please provide coding for following problem
Please provide coding for following problem  Please provide the coding for the following problem: You will write a java program that will read data... John Green 82 Jill White 97 The program will rad the data into three separate
question
question  i am using following one .please give me the correct one.i used grigorian calendar if(hour<=13) { i couldn't worked with this if condition please help me
Question
Question  Sir, give me a Java program to read data from keyboard up to names , sort in alphabetical order using bubble sort
question
question  Good Afternoon Sir, Please give me a client Server Socket programming using jsp and java with mysql connection
Please write code for this program in java and Explain it ? pl'sssssssss
Please write code for this program in java and Explain it ? pl'sssssssss  Question: We are given an array of 2n integers wherein each pair... array of 2n integers. Write one of the following methods: C/C++: int
PLEASE Help me write a Java program which will store, manipulate, and print student registration information.
PLEASE Help me write a Java program which will store, manipulate, and print student registration information.  HERES TEH QUESTION - I AM MISSING SOME..., ADDRESS AND ADMISSIONS CLASS PLEASE HELP!!! Write a Java program which
java question
java question  Please, give me sample program for insert Audio(sound) on Frame in swing in java
help me please
help me please   Hello I want helping for this question , Please Write a program that reads some friendsââ?¬â?¢ names, stores them in an array, and then prints out on the screen all friends who start by a particular letter
question
question  do you have any idea about the following concept,give me Java code for A COMPARATIVE STUDY ON PERSONALIZATION IN INFORMATION RETRIEVAL WITH SHARING OF THE CONCEPT BASED USER PROFILES using Java
please help me.
please help me.  How to read a properties file in java with a suitable example. Please send me. Thanks Trinath   Please visit the following link: Java read properties file
question
question  please give me the relevant modules and details to start java coding for "Deriving Concept-based User Profiles from Search Engine Logs" it's very urgent
question
question  Sir, How to stream video on one computer which is playing on another PC in LAN using java + socket / RMI . if you have any idea about that please help me and give the source code
please help me to solve this question about array
please help me to solve this question about array  write a program... character. The program should ignore the case of that character (uppercase or lowercase...() > 1) System.out.println("It is not character. Please enter

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.