Java Forums

Main Menu
Home
Today's Posts
FAQ
Search
Contact Us

Java Network
Linux Archive
Java Tips
Java Tips Blog

Sponsored Links





Welcome to the Java Forums.

You are currently viewing our boards as a guest which gives you limited access to view most discussions and access our other features. By joining our free community, you will:

  • have access to post topics
  • communicate privately with other members (PM)
  • not see advertisements between posts
  • have the possibility to earn one of our surprises if you are an active member
  • access many other special features that will be introduced later.

Registration is fast, simple and absolutely free so please, join our community today!

If you have any problems with the registration process or your account login, please contact us.

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 10-28-2008, 12:02 PM
keffie91's Avatar
Member
 
Join Date: Jun 2008
Location: The Netherlands
Posts: 35
keffie91 is on a distinguished road
[SOLVED] MVC question
Hello I am rewriting my Programming editor by the MVC Model

Code:
public class MainEditor { //Create Model, View and Controller public static void main(String[] args) { EditorModel model = new EditorModel(); EditorView view = new EditorView(model); EditorController controller = new EditorController(view, model); view.setVisible(true); } }
Code:
import java.awt.*; import java.awt.event.*; import javax.swing.*; import javax.swing.event.*; import java.lang.*; public class EditorView extends JFrame{ //Components private JMenuBar mbar = new JMenuBar(); private JToolBar tbar = new JToolBar(); private JTextArea area = new JTextArea(); private JTabbedPane tabbedpane = new JTabbedPane(); private JScrollPane scrollpane = new JScrollPane(area); // Menu's on Menubar private JMenu filemenu = new JMenu("File"); private JMenu editmenu = new JMenu("Edit"); private JMenu helpmenu = new JMenu("Help"); //Menu Items in the menu's on the MenuBar private JMenuItem newfile = new JMenuItem("New File"); private JMenuItem openfile = new JMenuItem("Open File"); private JMenuItem savefile = new JMenuItem("Save File"); private JMenuItem savefileas = new JMenuItem("Save File As"); private JMenuItem about = new JMenuItem("About"); private EditorModel e_model; public EditorView(EditorModel model){ //Set up the logic e_model = model; // Layout Components getContentPane().add(tbar,BorderLayout.NORTH); getContentPane().add(tabbedpane,BorderLayout.CENTER); setJMenuBar(mbar); mbar.add(filemenu);mbar.add(editmenu);mbar.add(helpmenu); filemenu.add(newfile);filemenu.add(openfile);filemenu.add(savefile);filemenu.add(savefileas); helpmenu.add(about); tabbedpane.addTab("Untitled",scrollpane); //Finalize Layout setTitle("DK Programming Editor"); setSize(900,900); //What has to happen when you click the cross in the right corner setDefaultCloseOperation(EXIT_ON_CLOSE); } void addMenuListener(ActionListener mal){ about.addActionListener(mal); } }
Code:
import java.awt.*; import java.awt.event.*; import javax.swing.*; public class EditorController { private EditorView e_view; private EditorModel e_model; /* Constructor */ public EditorController(EditorView view, EditorModel model){ // The controller needs to interact with the view and the model e_view = view; e_model = model; // Add Listeners view.addMenuListener(new MenuListener()); } // inner class MenuListener used to control the JMenuItems class MenuListener implements ActionListener{ public void actionPerformed(ActionEvent e){ JOptionPane.showMessageDialog(null, "DK Programming Editor"); } }//End inner class MenuListener }
Code:
public class EditorModel { }
The Model is not used until now, but my questions is: Is it possible to add more JMenuItems to MenuListener.

I tried to do this:

public void actionPerformed(ActionEvent e){
if(e.getSource() == about){
JOptionPane.showMessageDialog(null, "DK Programming Editor");
}
}

But that doesn't work. How can i solve that?

keffie91
__________________
Never give up!
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
Bookmark Post in Technorati
Reply With Quote
Sponsored Links
  #2 (permalink)  
Old 10-29-2008, 09:10 PM
serjant's Avatar
Senior Member
 
Join Date: Jun 2008
Location: Ukraine,Zaporozhye
Posts: 356
serjant is on a distinguished road
Send a message via ICQ to serjant Send a message via Skype™ to serjant
try this one
Code:
public void actionPerformed(ActionEvent e){ if(e.getActionCommand().equals("About")){ JOptionPane.showMessageDialog(null, "DK Programming Editor"); } }
Bookmark Post in Technorati
Reply With Quote
  #3 (permalink)  
Old 10-29-2008, 09:21 PM
keffie91's Avatar
Member
 
Join Date: Jun 2008
Location: The Netherlands
Posts: 35
keffie91 is on a distinguished road
Ok thanks this work.

keffie91
__________________
Never give up!
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
Bookmark Post in Technorati
Reply With Quote
Sponsored Links
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Question mark colon operator question orchid Advanced Java 8 11-27-2008 08:36 AM
ur help on my question jameela New To Java 4 10-13-2008 02:38 PM
JSP Question maheshkumarjava JavaServer Pages (JSP) and JSTL 1 03-29-2008 12:51 PM
a question slytheman Java Servlet 0 03-12-2008 06:11 AM
Need help on this question Deon New To Java 3 01-27-2008 05:58 PM


All times are GMT +3. The time now is 10:05 AM.


VBulletin, Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO ©2007, Crawlability, Inc.
Copyright ©2006 - 2007, www.java-forums.org