3 Replies - 1082 Views - Last Post: 30 October 2010 - 12:22 PM Rate Topic: -----

#1 kartikkp  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 10
  • Joined: 27-October 10

Java GUI

Posted 30 October 2010 - 09:57 AM

I'm trying to make tabs in the GUI program that I have but everytime that I run it, it says it's not initialized. I have tried to create a canvas but it wont read it and keeps saying its not initilized
the tabs are in 2 seperate classes and they are built over a main app that links it all together. Bellow is the code for the main app
the tabs should be linked as follows
1. detailPane with two textfields and one combo box
2. My instructor said to add a ScrollPane and then link a table to it using TableModel for the 2nd tab
along with the tabs right bellow should be a status label and another button that switches the tabs when clicked.



bellow is the code.

package MobileCalendar;

import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Component;
import java.awt.Container;
import java.awt.FlowLayout;
import java.awt.Frame;
import java.awt.Graphics;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.GridLayout;
import java.awt.Panel;
import java.awt.TextField;
import java.awt.event.ActionEvent;

import javax.swing.BorderFactory;
import javax.swing.JButton;
import javax.swing.JComponent;
import javax.swing.JLabel;
import javax.swing.JList;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTabbedPane;
import javax.swing.JTextArea;
import javax.swing.ListModel;
import javax.swing.border.BevelBorder;
import javax.swing.event.ChangeEvent;


public class MobileCalendar extends javax.swing.JApplet implements java.awt.event.ActionListener, javax.swing.event.ChangeListener {

	
	

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;

	private DetailPane detailPane;
	
	private EventList myList;
	
	private JButton newEventButton;
	
	private JLabel statusLabel;
	
	private JScrollPane summaryPane;
	
	private JTabbedPane tabs;
	
	Graphics g; 
	
	JPanel canvas;
	
	
	/*
	 * Handles all button clicks
	 */
	public void actionPerformed(ActionEvent evt) {
		String command = evt.getActionCommand();
		if (command.equals("Enter New Event")){
			
		}
		
	}
	
	
	
	/*(
	 * Lay out the applet with status label, tabbed pane, and new event button
	 */
	public void init(){
		JPanel detailPane = new JPanel(new BorderLayout());
		JTabbedPane tabs = new JTabbedPane();
		detailPane.add(tabs);
		detailPane.add(newEventButton);
		detailPane.add(statusLabel);
		
		
		/*
		Container pane;
		pane.setLayout(new GridBagLayout());
		GridBagConstraints c = new GridBagConstraints();
		newEventButton = new JButton("CLICK FOR NEW EVENT");
		c.fill = GridBagConstraints.HORIZONTAL;
		c.ipady = 40;      //make this component tall
		c.weightx = 0.0;
		c.gridwidth = 3;
		c.gridx = 0;
		c.gridy = 1;
		pane.add(newEventButton, c);
		*/
		

	}

	/*
	 *     If 'tabs' has been changed to the detail view and there is a 
	 *     selected summary, display its details on the Details view
	 */
	public void stateChanged(ChangeEvent evt) {
		// TODO Auto-generated method stub
		
	}

}


Edited by Dogstopper: :code:

This post has been edited by Dogstopper: 30 October 2010 - 12:44 PM


Is This A Good Question/Topic? 0
  • +

Replies To: Java GUI

#2 bcranger  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 252
  • View blog
  • Posts: 1,199
  • Joined: 01-February 10

Re: Java GUI

Posted 30 October 2010 - 12:12 PM

You have to initialize it just like the error message says...for example:
private DetailPane dp = new DetailPane();


Was This Post Helpful? 0
  • +
  • -

#3 kartikkp  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 10
  • Joined: 27-October 10

Re: Java GUI

Posted 30 October 2010 - 12:19 PM

View Postbcranger, on 30 October 2010 - 11:12 AM, said:

You have to initialize it just like the error message says...for example:
private DetailPane dp = new DetailPane();




hey that's not really necessary because it's already accomplished abvoe in the DetailPane detailPane and its just another object created. I've actually updated and gotten this far now: http://grab.by/78JC

with the code:
public void init(){
		JFrame frame = new JFrame("FrameDemo");
		JPanel mobCalendar =  new JPanel();
		tabs = new JTabbedPane();
		JPanel panel1 = detailPane;
		JScrollPane panel2 = summaryPane;

		
		tabs.addTab("Details",panel1);
		tabs.addTab("Events", panel2);
		
		mobCalendar.add(tabs);
		frame.add(mobCalendar);
		frame.pack();
		frame.setVisible(true);

	}


the issue is that the tabs are not showing a pannel, idk how to set the size and they are supposed to be left and right
Was This Post Helpful? 0
  • +
  • -

#4 bcranger  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 252
  • View blog
  • Posts: 1,199
  • Joined: 01-February 10

Re: Java GUI

Posted 30 October 2010 - 12:22 PM

Whoa, you should not have two things named detailPane...you have one that you declare as a class variable and one that you declare locally...and you MUST initialize them, there is no point to even declaring them if you are not going to initialize and use them.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1