Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

JMenu and interaction  RSS feed

 
Gizzmo Zeuzere
Ranch Hand
Posts: 45
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi
I have a problem (logic). I have 2 classes, one which deals with an JFrame (the main class) ans an other which deals with the Menu. And i want that when i do "create a new File" or "open" that it interacts with the Frame. But I don't know how to do that !
(and sorry for my english)
[ March 07, 2002: Message edited by: Gizzmo Zeuzere ]
 
Gregg Bolinger
Ranch Hand
Posts: 15304
6
Chrome IntelliJ IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Well, without know exactly what you are trying to do with you Program, I will say this: The power of JAVA in part lies in it's structure. What I mean is have more than one class file for your program is great. Really, everything in JAVA is a CLASS file. When you create a new instance of a JMenuBar, JMenuBar menu = new JMenuBar() you are actually using a CLASS file called JMenuBar. So if you have a Class file called MyMenuBar and extend JMenuBar, then you would instead of the above say, MyMenuBar menu = new MyMenuBar(). Basically doing the same thing, exept you are extending all the methods of the JMenuBar Class into your own class.
Then you just have to add event listeners to your menu items that will interact with your other class files.
Try and let us know what you plan on doing with your Menu Options and we can better assist you on code construction.
 
Gizzmo Zeuzere
Ranch Hand
Posts: 45
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
this first class is my JFrame
public class AGL12 extends JFrame{
protected int longueur,largeur;
public Container contConsole,contExplorerFichier,contListeMethode,contText;
public JInternalFrame f1,f2,f3,f4;
public JTextArea console,document;
public JDesktopPane dp;
public JScrollPane consolePane;
public JMenuBar barmenu;
public AGL12() {}
public void creationFenetre()
{
addWindowListener(new WindowAdapter()
{
public void windowClosing(WindowEvent we)
{
System.exit(0);
}
});

Toolkit kit = Toolkit.getDefaultToolkit();
Dimension screenSize = kit.getScreenSize();
largeur=screenSize.height-10;
longueur=screenSize.width;
setSize(longueur,largeur);
setTitle("JavaCompilator ");
dp = new JDesktopPane();
setContentPane(dp);
contConsole=new Container();
contExplorerFichier=new Container();
contListeMethode=new Container();
contText=new Container();
f1=new JInternalFrame("",true,true,true,true);
f2=new JInternalFrame("",true,true,true,true);
f3=new JInternalFrame("Nouveau Document",true,true,true,true);
f4=new JInternalFrame("Console",true,true,true,true);
f1.setSize(longueur/10,(largeur-largeur/5)/2);
f1.setLocation(0,0);
f2.setSize(longueur/10,(largeur-largeur/5)/2);
f2.setLocation(0,2*largeur/5);
f3.setSize(9*longueur/10,4*largeur/5);
f3.setLocation(longueur/10,0);
f4.setSize(longueur,largeur/9);
f4.setLocation(0,4*largeur/5);
Vector v=new Vector();
v.add("a");
v.add("b");
v.add("c");
JTree jt1=new JTree(v);
JTree jt2=new JTree(v);
document=new JTextArea("c",20,20);
contExplorerFichier=f1.getContentPane();
contExplorerFichier.add(jt1);
contListeMethode=f2.getContentPane();
contListeMethode.add(jt2);
contText=f3.getContentPane();
contText.add(document);
contConsole=f4.getContentPane();
console=new JTextArea(2,1);
console.setText("Bleu");
consolePane=new JScrollPane(console);
contConsole.setSize(longueur,largeur/10);
contConsole.add(consolePane);
f1.setVisible(true);
f2.setVisible(true);
f3.setVisible(true);
f4.setVisible(true);
barmenu=new JMenuBar();
JMenu fichier=(new GestionMenuFichier()).createMenuFichier(f3);
barmenu.add(fichier);
JMenu edition=(new GestionMenuEdition()).createMenuEdition();
barmenu.add(edition);
setJMenuBar(barmenu);
dp.add(f1);
dp.add(f2);
dp.add(f3);
dp.add(f4);
show();
}
public static void main(String[] args) {
AGL12 notAgl=new AGL12();
notAgl.creationFenetre();
}
}
--------------------------
//the Menu File
public class GestionMenuFichier{
public GestionMenuFichier() {

}
public JMenu createMenuFichier(JInternalFrame fr)
{
JMenu mFile = new JMenu("File");
mFile.setMnemonic('f');
Action actionNew = new AbstractAction("Nouveau Fichier")
{
public void actionPerformed(ActionEvent e)
{
// I want create a new JTextArea in my JFrame
}
};
.
.
.
I don't know how to do the actionPerformed
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!