Go Back   CodingForums.com > :: Server side development > Java and JSP

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 03-10-2011, 01:47 PM   PM User | #1
Quadra
New to the CF scene

 
Join Date: Mar 2011
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Quadra is an unknown quantity at this point
Java JTabbedPane

Hello,

I made a Java GUI with a JTabbedPane. At the top i got three tabs. Each tabs fills the space with an seperate class, extensions of JPanel.
This is the code of the mainfile:
Code:
package gui;
import java.util.*;
import java.io.IOException;
import java.lang.*;
import java.awt.*;

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

import data.*;


public class KGUI extends JFrame implements Observer{

	private JTabbedPane tabbedPane;
	private JComponent pp, kp, okp;
	private Vereniging v;
	
	public KGUI (Vereniging vereniging) {
		super("Kringindeling Generator");
		this.v = vereniging;
		v.addObserver(this);
		init();
		makeGUI();
	}
	

	public void init() {   
		setLayout(new BorderLayout()); // verander naar FlowLayout
		this.getContentPane().setComponentOrientation(ComponentOrientation.RIGHT_TO_LEFT);
		setExtendedState(Frame.MAXIMIZED_BOTH);
		setVisible(true);// laat het Frame zien
		addWindowListener(new WindowAdapter() {
			@Override	// annotatie voor de compiler!
			public void windowClosing(WindowEvent e) {
			System.exit(0);
		}});
	}
	
	public void makeGUI() {
		
	    try {
	        SwingUtilities.invokeAndWait(new Runnable() {
	          public void run() {
	            makeTabs();
	          }
	        });
	      } catch (Exception exc) {
	        System.out.println("Can't create because of " + exc);
	      }
	}
	
	
	public void makeTabs() {
		JTabbedPane tabbedPane = new JTabbedPane();
		tabbedPane.addTab("Personen",  new PersoonPanel(v));
		tabbedPane.setMnemonicAt(0, KeyEvent.VK_1);
		
		tabbedPane.addTab("Kringen", new KringPanel(v));
		tabbedPane.setMnemonicAt(1, KeyEvent.VK_2);

		tabbedPane.setTabLayoutPolicy(JTabbedPane.SCROLL_TAB_LAYOUT);
		this.add(tabbedPane);
		setVisible(true);
	}


	//@Override
	//public void update(Observable arg0, Object arg1) {
	//	v = (Vereniging) arg0;
	//}
}
In each of panels there can be changed something. Therefore I have by each class a ActionListener. This ActionListeners changes something in a seperate class, which is also implementing the class Observable.

All classes which extends the JPanel are Observers from this class. So, if anything will change, everything from that panel will be redrawed.

My questions are:
1. Is this architecture oke? Tabs, JPanels on that tabs, nested ActionListeners by the panels, an Observer-architecture?

This, because I have a problem with redrawing. If I change something, it will call the function update from each class. But, then all classes will update and I won't get the information from the right tab for me.
Quadra is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

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

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 09:04 PM.


Advertisement
Log in to turn off these ads.