Java Help
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me

The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.

Go Back   Dev Shed ForumsProgramming LanguagesJava Help

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old November 6th, 2012, 08:09 AM
new to java new to java is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Nov 2012
Posts: 2 new to java User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 46 m 4 sec
Reputation Power: 0
Homework - Frame won't open?

I am new and very uneducated as far as Java goes, but I wanted to try it. My teacher gave me the option to program my project, and I accepted. I typed up this code to make a frame full of buttons that when clicked on would give information. However, now whenever I run it, there are no errors, but it terminates immediately.

What's happening?

Here is the code:



import java.awt.ComponentOrientation;
import java.awt.Dimension;
import java.awt.GridLayout;
import java.awt.Window;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.*;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;

public abstract class Frame extends JFrame implements ActionListener {

public void frame(){

final JFrame frame = new JFrame();

frame.setSize(1000,700);

frame.setVisible(true);

frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

frame.setLocationRelativeTo(null);

frame.setTitle("Eukariotic Cell Information");




JLabel label = new JLabel("Click on what you would like to learn about.");



final JPanel panel = new JPanel();

panel.setLayout(new GridLayout(3,4,50,50));




frame.add(panel);

panel.setComponentOrientation(ComponentOrientation.LEFT_TO_RIGHT);


JButton cellmembrane = new JButton("Cell Membrane");

cellmembrane.addActionListener(this);

new ActionListener() {
public void actionPerformed(ActionEvent e) {

frame.remove(panel);
JPanel panel2 = new JPanel();

JLabel cellmembraneinfo = new JLabel("Info on Cell membrane");

panel2.add(cellmembraneinfo);

frame.add(panel2);

}
};





JButton mitochondrion = new JButton("Mitochondrion");

mitochondrion.addActionListener(this);

new ActionListener() {
public void actionPerformed(ActionEvent e) {

frame.remove(panel);
JPanel panel3 = new JPanel();

JLabel mitochondrioninfo = new JLabel("Info on Mitochondrion");

panel3.add(mitochondrioninfo);

frame.add(panel3);

}
};




JButton ribosomes = new JButton("Ribosomes");

ribosomes.addActionListener(this);


new ActionListener() {
public void actionPerformed(ActionEvent e) {

frame.remove(panel);
JPanel panel4 = new JPanel();

JLabel ribosomesinfo = new JLabel("Info on Ribosomes");

panel4.add(ribosomesinfo);

frame.add(panel4);

}
};



JButton roughER = new JButton("Rough ER");

roughER.addActionListener(this);

new ActionListener() {
public void actionPerformed(ActionEvent e) {

frame.remove(panel);
JPanel panel5 = new JPanel();

JLabel roughERinfo = new JLabel("Info on Rough ER");

panel5.add(roughERinfo);

frame.add(panel5);

}
};

JButton smoothER = new JButton("Smooth ER");

smoothER.addActionListener(this);

new ActionListener() {
public void actionPerformed(ActionEvent e) {

frame.remove(panel);
JPanel panel6 = new JPanel();

JLabel smoothERinfo = new JLabel("Info on Smooth ER");

panel6.add(smoothERinfo);

frame.add(panel6);

}
};



JButton golgiapparatus = new JButton("Golgi Apparatus");

golgiapparatus.addActionListener(this);

new ActionListener() {
public void actionPerformed(ActionEvent e) {

frame.remove(panel);
JPanel panel7 = new JPanel();

JLabel golgiapparatusinfo = new JLabel("Info on Golgi Apparatus");

panel7.add(golgiapparatusinfo);

frame.add(panel7);

}
};

JButton lysosomes = new JButton("Lysosomes");

lysosomes.addActionListener(this);

new ActionListener() {
public void actionPerformed(ActionEvent e) {

frame.remove(panel);
JPanel panel8 = new JPanel();

JLabel lysosomesinfo = new JLabel("Info on Lysosomes");

panel8.add(lysosomesinfo);

frame.add(panel8);

}
};


JButton cytoskeleton = new JButton("Cytoskeleton");

cytoskeleton.addActionListener(this);

new ActionListener() {
public void actionPerformed(ActionEvent e) {

frame.remove(panel);
JPanel panel9 = new JPanel();

JLabel cytoskeletoninfo = new JLabel("Info on Cytoskeleton");

panel9.add(cytoskeletoninfo);

frame.add(panel9);

}
};


JButton nucleus = new JButton("Nucleus");

nucleus.addActionListener(this);


new ActionListener() {
public void actionPerformed(ActionEvent e) {

frame.remove(panel);
JPanel panel10 = new JPanel();

JLabel nucleusinfo = new JLabel("Info on Nucleus");

panel10.add(nucleusinfo);

frame.add(panel10);

}
};

JButton cellwall = new JButton("Cell Wall");

cellwall.addActionListener(this);

new ActionListener() {
public void actionPerformed(ActionEvent e) {

frame.remove(panel);
JPanel panel11 = new JPanel();

JLabel cellwallinfo = new JLabel("Info on Cell Wall");

panel11.add(cellwallinfo);

frame.add(panel11);

}
};


JButton vacuole = new JButton("Vacuole");

vacuole.addActionListener(this);

new ActionListener() {
public void actionPerformed(ActionEvent e) {

frame.remove(panel);
JPanel panel12 = new JPanel();

JLabel vacuoleinfo = new JLabel("Info on Vacuole");

panel12.add(vacuoleinfo);

frame.add(panel12);

}
};


JButton plastids = new JButton("Plastids");

plastids.addActionListener(this);

new ActionListener() {
public void actionPerformed(ActionEvent e) {

frame.remove(panel);
JPanel panel13 = new JPanel();

JLabel plastidsinfo = new JLabel("Info on Plastids");

panel13.add(plastidsinfo);

frame.add(panel13);

}
};

JButton chloroplasts = new JButton("Chloroplasts");

chloroplasts.addActionListener(this);

new ActionListener() {
public void actionPerformed(ActionEvent e) {

frame.remove(panel);
JPanel panel14 = new JPanel();

JLabel chloroplastsinfo = new JLabel("Info on Chloroplasts");

panel14.add(chloroplastsinfo);

frame.add(panel14);

}
};

JButton nucleolus = new JButton("Nucleolus");

nucleolus.addActionListener(this);

new ActionListener() {
public void actionPerformed(ActionEvent e) {

frame.remove(panel);
JPanel panel15 = new JPanel();

JLabel nucleolusinfo = new JLabel("Info on Nucleolus");

panel15.add(nucleolusinfo);

frame.add(panel15);

}
};

JButton nuclearmembrane = new JButton("Nuclear Membrane");

nuclearmembrane.addActionListener(this);

new ActionListener() {
public void actionPerformed(ActionEvent e) {

frame.remove(panel);
JPanel panel16 = new JPanel();

JLabel nuclearmembraneinfo = new JLabel("Info on Nuclear Membrane");

panel16.add(nuclearmembraneinfo);

frame.add(panel16);

}
};


panel.add(label);

panel.add(cellmembrane);

panel.add(mitochondrion);

panel.add(ribosomes);

panel.add(roughER);

panel.add(smoothER);

panel.add(golgiapparatus);

panel.add(lysosomes);

panel.add(cytoskeleton);

panel.add(nucleus);

panel.add(cellwall);

panel.add(vacuole);

panel.add(plastids);

panel.add(chloroplasts);




}






public static void main(String[]args){









}










}

Reply With Quote
  #2  
Old November 6th, 2012, 08:39 AM
jasondj jasondj is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jun 2010
Posts: 93 jasondj User rank is Sergeant Major (2000 - 5000 Reputation Level)jasondj User rank is Sergeant Major (2000 - 5000 Reputation Level)jasondj User rank is Sergeant Major (2000 - 5000 Reputation Level)jasondj User rank is Sergeant Major (2000 - 5000 Reputation Level)jasondj User rank is Sergeant Major (2000 - 5000 Reputation Level)jasondj User rank is Sergeant Major (2000 - 5000 Reputation Level) 
Time spent in forums: 1 Day 5 h 54 m 51 sec
Reputation Power: 24
I'm no GUI expert, but one problem I can see right away is that your main method is empty. When you tell Java to run, its going to start by looking at your main method and execute what is inside. I would imagine that if you want the frame to show up you would need to instantiate it and setVisible to true.

I think that googling a few simple AWT examples / sample code would get you what you need.

Edit:
Also, in the future please consider using CODE tags (described in the sticky here: http://forums.devshed.com/java-help-9/all-users--how-to-post-a-question-147056.html). They will make your code a lot more readable and that makes it easier for others to help you.

Reply With Quote
  #3  
Old November 6th, 2012, 09:05 AM
new to java new to java is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Nov 2012
Posts: 2 new to java User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 46 m 4 sec
Reputation Power: 0
Quote:
Originally Posted by jasondj
I'm no GUI expert, but one problem I can see right away is that your main method is empty. When you tell Java to run, its going to start by looking at your main method and execute what is inside. I would imagine that if you want the frame to show up you would need to instantiate it and setVisible to true.

I think that googling a few simple AWT examples / sample code would get you what you need.

Edit:
Also, in the future please consider using CODE tags (described in the sticky here: . They will make your code a lot more readable and that makes it easier for others to help you.




Thank you for responding. So how would I go about instantiating it in my main method? It is static, so the (this) in the action listeners won't function if I just drag the whole thing in. Should I just re-declare it? Sorry if these are really stupid questions, but this is the first program I have ever really made in Java, so I don't quite know how to make things work yet.

Thanks.

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming LanguagesJava Help > Homework - Frame won't open?

Developer Shed Advertisers and Affiliates



Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  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

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 


Powered by: vBulletin Version 3.0.5
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.

© 2003-2013 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap