Share on Google+Share on Google+

sunil burman
Core java
2 Answer(s)      7 years ago
Posted in : Applet

Ads

View Answers

June 1, 2009 at 5:29 PM


Hi Friend,

Try the following code:

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

public class MenuExample extends JApplet implements WindowListener,ActionListener {
static final String Key1 = "Key1";
static final String Key2 = "Key2";
JFrame window,window1;
JMenuBar menuBar = new JMenuBar();
JMenu menu = new JMenu("Shortcut Keys");
JMenuItem item1 = new JMenuItem("ctrl+C");
JMenuItem item2 = new JMenuItem("ctrl+v");
JLabel label1,label2;

public void init() {
menuBar.add(menu);
menu.add(item1);
menu.add(item2);
item1.setActionCommand(Key1);
item1.addActionListener(this);

item2.setActionCommand(Key2);
item2.addActionListener(this);

label1=new JLabel("This key copies the text.");
label2=new JLabel("This key paste the text.");
JPanel contentPane = new JPanel();
contentPane.setLayout(new BorderLayout());
contentPane.add(menuBar, BorderLayout.NORTH);
setContentPane(contentPane);
window = new JFrame("Window1");
window.addWindowListener(this);
window1 = new JFrame("Window2");
window1.addWindowListener(this);
}
public void windowClosing(WindowEvent e) {
}

public void windowClosed(WindowEvent e) {
}

public void windowOpened(WindowEvent e) {
}

public void windowIconified(WindowEvent e) {

}

public void windowDeiconified(WindowEvent e) {

}

public void windowActivated(WindowEvent e) {

}

public void windowDeactivated(WindowEvent e) {

}
public void actionPerformed(ActionEvent e) {
if (e.getActionCommand() == Key1) {
window.setVisible(true);
window.getContentPane().add(label1);

} else if(e.getActionCommand() == Key2) {
window1.setVisible(true);
window1.getContentPane().add(label2);

}
}
}


June 1, 2009 at 5:30 PM


continue.............

Call the above applet with the following html code:

<html>
<body>
<h1>Java Applet Demo</h1>
<applet code=WindowEventDemo.class width=300 height=150>
</applet>
</body>
</html>

Thanks









Related Tutorials/Questions & Answers:
core java
core java  how to display characters stored in array in core java
core java
core java  basic java interview question
Advertisements
CORE JAVA
CORE JAVA  CORE JAVA PPT NEED WITH SOURCE CODE EXPLANATION CAN U ??   Core Java Tutorials
core java
core java  i need core java material   Hello Friend, Please visit the following link: Core Java Thanks
core java
core java  Hi, can any one expain me serialization,Deseralization and exterenalization in core java
core java
core java  Hi, can any one exain me the concept of static and dynamic loading in core java
Core JAva
Core JAva  how to swap 2 variables without temp in java
core java
core java  how can we justify java technology is robust
CORE JAVA
CORE JAVA  What is Garbage collection in java? What is the role of a developer for garbage collection
core java
core java  its compulsory to save file name and class name is same in java
Core Java
Core Java  How to execute cmd command through java?? Give Code of them
core java
core java  write a java program to view product details from product table
Core Java
Core Java  Hi, Can any one please share the code for Binary search in java without using builtin function
Core Java
Core Java  Please write a Java Program to design login form and store the values in file & validate and display the MainForm
core java
core java  In java primitive variables will get its default value automatically after declaration. Then why it is mandatory to initialize a variable before using
core java
core java  Hello sir,What is logic behinde the core java programms,How may programmas are there,for example,sorting of two numbers,grade of the student details,fibonice serice,paldroma,incremting of the program,asscedding
core java
core java  Hello sir,What is logic behinde the core java programms,How may programmas are there,for example,sorting of two numbers,grade of the student details,fibonice serice,paldroma,incremting of the program,asscedding
Core Java
Core Java  Hi, can any one please tell me the uses of return type,"Super" and "this" calling statement in Java?? why do we required this,super calling statement?? why return type is required
Core Java
Core Java  Hi, Can any one please expain me why derived data types are required in java as we have primitive data types with us
Core Java
Core Java  Hi, Can any one please expain me why derived data types are required in java as we have primitive data types with us
Core Java
Core Java  How to load class dynamically in java ?   To load class dynamically you can use Class class method Class.forName("abc.xyz.MyClass"); This method load the given class at run time
Core Java
Core Java  what is a class
Core Java
Core Java   How can i write own compile time and runtime exceptions in java   Hello Friend, Please visit the following links: http://www.roseindia.net/java/exceptions/how-to-throw-exceptions.shtml http
Core Java
Core Java  Is Java supports Multiple Inheritance? Then How ?   Hi Friend, Java does not support multiple inheritance but it can be achieved by using the interface. In Java, Multiple Inheritance can be achieved through
Core java
Core java  How to use hyperlink that is href tag in core java without swing, frames etc. My code is StringBuffer oBodyStringBuffer = new StringBuffer("Message Classification: Restricted.\n\n
CORE JAVA
CORE JAVA  What is called Aggregation and Composition
core java
core java  surch the word in the given file
Core Java
Core Java   Hi, Can any one please tell me the program to print the below matrix in a spiral order. 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 Thanks a lat in advance
core java
core java  I am having 10 countries in the data base as back end.in front end i am having a button in web page like SHOWCOUNTRIESLIST so i need java code how to retrive that 10 countries from back end to my page,,pls help me
core java - Java Beginners
core java  i want to get java projects in core java
core java
core java  how to write or update into excel file using...; Please visit the following links: http://www.roseindia.net/tutorial/java/poi/insertIntoExcelFileData.html http://www.roseindia.net/answers/viewqa/Java
Tutorials   
Java Spring Hibernate Struts Training Error in calling javascript function from java prg Creating an Applet java program Display Java in JSP Draw bufferimage in jpanel using netbeans Moving Applet Problem c programming Attendence Management system java program of different shapes help applet printing p applet dought Help please, some strange errors Write an applet to display scrolling image in an applet window using thread. Simple Java applet that need usernam, password and textfield. conversion Applet java program java program java program scrolling text in applet java java applet java applet project in java using applet and servlet...which tool i should use?eclipse or netbeans? java user input to database user input to database user input to database button to accept user input jframe what is web .config method Can any one please help me in this ,,,,,,, need java code for this ,,,,please anyone applet question Write an Applet which display current date and time on the web page?? Write an Applet which display current date and time on the web page?? Java Applet - Adding a Button to Decrease a Total Applet Application how to drag top most images which is draw on applet. convert java Application to Java Applet convert java Application to Java Applet Problem In applet Its run on browser but hang and blinking when image is draging some where. how to access database in applet How to add dropdown list in a row of a sort table applet? java project topics plz anyone can solve my Layout Manager Project Guidance applet is running but no display

Ads

 
Advertisement null

Ads