wood burning stoves 2.0*
The moose likes Swing / AWT / SWT and the fly likes simpleeditor Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "simpleeditor" Watch "simpleeditor" New topic
Author

simpleeditor

anitha nagarajan
Greenhorn

Joined: Aug 04, 2004
Posts: 3
thanks 4 replying i had created a code for displaying a frame with menuBar Toolbar ,PopupMenu& an empty textArea but i cann't get the o/p properly.can anybody help me
follows code


import javax.swing.*;
import javax.swing.event.*;
import java.awt.*;
import java.awt.event.*;
public class Taction extends JFrame
{
CutAction cutA=null;
PasteAction pasteA=null;
Container con=null;
JTextArea text=null;
JPopupMenu pop=null;
Icon cuti=new ImageIcon("cut.gif");
Icon pastei=new ImageIcon("paste.gif");
public Taction ()
{
super("Taction Frame");
con=this.getContentPane();
JPanel panel=new JPanel(false);
con.add(panel,BorderLayout.NORTH);
panel.setLayout(new GridLayout(2,1));
JMenuBar menu=new JMenuBar();
panel.add(menu);
JMenu file=new JMenu("File");
JMenu edit=new JMenu("Edit");
menu.add(file);
menu.add(edit);
JToolBar tool=new JToolBar();
panel.add(tool);
cutA=new CutAction("cut",cuti);
pasteA=new PasteAction("paste",pastei);
JMenuItem cutitem=edit.add(cutA);
JMenuItem pasteitem=edit.add(pasteA);
JButton cutb=tool.add(cutA);
JButton pasteb=tool.add(pasteA);
cutb.setText("");
pasteb.setText("");
text=new JTextArea();
con.add(text);
pop=new JPopupMenu("pop");
JMenuItem cutpop=pop.add(cutA);
JMenuItem pastepop=pop.add(pasteA);
PopupMenuListener p=new PopupMenuListener();
text.addMouseListener(p);
this.addWindowListener(new WindowEventHandler());
setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
setSize(400,400);
show();
}
class CutAction exdtends AbstractAction{
public CutAction(String label,Icon icon)
{
super(label,icon);
}
public void actionPerformed(ActionEvent ae)
{
text.cut();
}
}

class PasteAction exdtends AbstractAction{
public PasteAction(String label,Icon icon)
{
super(label,icon);
}
public void actionPerformed(ActionEvent ae)
{
text.paste();
}
}
class PopupMenuListener extends MouseAdapter
{
public void mousePressed(MouseEvent m)
{
showpop(m);
}
public void mouseReleased(MouseEvent m)
{
showpop(m);
}
private void showpop(MouseEvent m)
{
if(m.isPopupTrigger()){
pop.show(m.getComponent(),m.getX(),m.getY());
}
}
}
class WindowEventHandler extends WindowAdapter{
public void windowClosing(WindowEvent w)
{
System.exit(0);
}
}
public static void main(String[] args)
{
Taction t=new Taction();
}
}
Liam Tiarnach
Ranch Hand

Joined: Aug 06, 2004
Posts: 51
What do you mean with O/P ?


- Liam...<br />- ' He who never sleeps... '
 
wood burning stoves
 
subject: simpleeditor
 
Similar Threads
Right-Click on JMenuItem
JMenuItem enable
Exception Null
JMenu problem
Aligning Text and Images in Pop up Menus