Welcome to Dream.In.Code
Become a Java Expert!

Join 149,478 Java Programmers for FREE! Get instant access to thousands of Java experts, tutorials, code snippets, and more! There are 1,654 people online right now. Registration is fast and FREE... Join Now!




JAVA GUI

 
Reply to this topicStart new topic

JAVA GUI, capturing of animals.

matome
18 May, 2007 - 04:37 AM
Post #1

New D.I.C Head
*

Joined: 22 Apr, 2007
Posts: 10


My Contributions
Using Java’s GUIs, design a nature documentation program that will users to capture information about a particular animal as well as it corresponding picture. The information that can be captured includes the name of the animal or species, its habitat, and general description or behavioral patterns.



This is my code so far,starting simply with capturing two animals.
please help

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

public class Gui extends JFrame
{

private JLabel label1,label2,label3;
private JTextField text1,text2,text3;
private JButton button1,button2;

public Gui(String title)
{

setTitle("Animal Capturing");
super(title);

Container pane = this.getContentPane();
pane.setLayout(new FlowLayout());
this.setSize(400, 300);


label1 =new JLabel("ANIMAL HABITAT");
label2 =new JLabel("SPECIES");
label3 =new JLabel("life's span");
text1 =new JTextField(10);
text2 =new JTextField();
text3 =new JTextField();
button1 =new JButton("ok");
button2 =new JButton("ok");

pane.add(label1);
pane.add(text1);

pane.add(label2);
pane.add(text2);

pane.add(label3);
pane.add(text3);

pane.add(button1);
pane.add(button2);

}
public static void main(String args[])
{
Gui gui = new Gui("Animal Capturing");
gui.setVisible(true);

}

}









User is offlineProfile CardPM
+Quote Post

spullen
RE: JAVA GUI
18 May, 2007 - 07:14 AM
Post #2

D.I.C Regular
Group Icon

Joined: 22 Mar, 2007
Posts: 330



Thanked: 1 times
Dream Kudos: 50
My Contributions
What's the specific problem that you are having? And next time use code tags when posting code.

When I was learning how to program GUI's in Java I used a DisplayWindow, Panel, Driver model. The DisplayWindow was pretty basic, just the properties of the window. And the Panel would hold all the components, then it would be put on the DisplayWindow.
I made a sample program which you can go by I hope it helps:
DisplayWindow:
CODE

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

public class DisplayWindow extends JFrame{
  
  private Container c;
  
  public DisplayWindow(){
    super("Sample Program");
    c = this.getContentPane();
  }
  
  public void addPanel(JPanel p){
    p.setPreferredSize(new Dimension(2000, 2000));
    c.add(p);
  }
  
  public void showFrame(){
    this.pack();
    this.setVisible(true);
    this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  }
}

The Panel (GraphicsPanel), this is where your code and functionality go:
CODE

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

public class GraphicsPanel extends JPanel implements ActionListener{
  
    
  //Label
  JLabel aLabel = new JLabel("This is a label");

  //Button
  JButton aButton = new JButton("This is a button);

  
  //Textfield
  JTextField aTextField = new JTextField(8);


  public GraphicsPanel(){
    this.add(aLabel);
    this.add(aButton);
    this.add(aTextField);
    aButton.addActionListener(this);
  }

  public void actionPerformed(ActionEvent e){
    if(e.getSource == aButton){
        aLabel.setText("I changed the text of the label");
        //do other stuff in the actionPerformed place
      }
  }
}

And here is the driver for the program:
CODE

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

public class GraphicsDriver{
  public static void main(String[] args){
    DisplayWindow d = new DisplayWindow();
    GraphicsPanel p = new GraphicsPanel();
    d.add(p);
    d.showFrame();
  }
}

Hopefully this helps, essentially you could just replace the code from the sample I gave you, and add stuff to it, but actually try to see how it works.
User is offlineProfile CardPM
+Quote Post

Fast ReplyReply to this topicStart new topic
Time is now: 1/7/09 03:32PM

Be Social

Dream.In.Code RSS Feed Dream.In.Code LinkedIn Group Follow Us On Twitter

Live Java Help!

Java Tutorials

Reference Sheets

Java Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month