File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Swing / AWT / SWT and the fly likes Won't Display Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "Won Watch "Won New topic
Author

Won't Display

Chase Becicka
Greenhorn

Joined: Feb 16, 2004
Posts: 23
I have been trying to figure out why when I execute this code all I get is a little bar at the top of the screen without any of my Labels or Buttons please help with a debug



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

public class inventFrame extends JFrame
{
public void BankingGUIFrame()
{
setTitle("Teller Program");
Toolkit tk = Toolkit.getDefaultToolkit();
Dimension d = tk.getScreenSize();
int height = 200;
int width = 267;
setBounds((d.width-width)/2, (d.height-height)/2, width, height);
setResizable(true);
addWindowListener(new WindowAdapter(){
public void windowClosing(WindowEvent e){
System.exit(0);
}
});
Container contentPane = getContentPane();
JPanel panel = new BankingGUIPanel();
contentPane.add(panel);
}


public static void main(String[] args)
{
JFrame frame = new inventFrame();
frame.show();
}
}


class BankingGUIPanel extends JPanel implements ActionListener
{
private JTextField custNumTF, custNameFTF, custNameMITF, custNameLTF;
private JLabel custNumL, custNameFL, custNameMIL, custNameLL;
private JButton exitButton;


public BankingGUIPanel()
{
JPanel displayPanel = new JPanel();
displayPanel.setLayout(new FlowLayout(FlowLayout.RIGHT));

custNumL = new JLabel("Customer Number: ");
custNameFL = new JLabel("First Name: ");
custNameMIL = new JLabel("Middle Inital: ");
custNameLL = new JLabel("Last Name: ");

custNumTF = new JTextField(10);
custNameFTF = new JTextField(10);
custNameMITF = new JTextField(10);
custNameLTF = new JTextField(10);

displayPanel.add(custNumL);
displayPanel.add(custNumTF);
displayPanel.add(custNameFL);
displayPanel.add(custNameFTF);
displayPanel.add(custNameMIL);
displayPanel.add(custNameMITF);
displayPanel.add(custNameLL);
displayPanel.add(custNameLTF);

JPanel buttonPanel = new JPanel();
buttonPanel.setLayout(new FlowLayout(FlowLayout.RIGHT));
exitButton = new JButton("Exit");
buttonPanel.add(exitButton);

exitButton.addActionListener(this);

setLayout(new BorderLayout());
add(displayPanel, BorderLayout.CENTER);
add(buttonPanel, BorderLayout.SOUTH);
}
public void actionPerformed(ActionEvent e)
{
Object source = e.getSource();

if (source == exitButton)
System.exit(0);

}



}
Ransika deSilva
Ranch Hand

Joined: Feb 18, 2003
Posts: 524
Hi,
I figured out why it is not appearing. You have to change the main method.

BankingGUIFrame() is a method and it is not a constructor, so it will not be automatically created when you create an object of the class inventFrame. To call that you need an instance of the class inventFrame, you can't have Frame frame = new inventFrame(); and use that frame instance to call the BankingGUIFrame() cause that reference can't call that method.
Hope you got the point. BTW, it's better you name the classes according to the Hungerian Notation (the 1st letter of all the words should be in capital, example: InventFrame), Have a nice day...


SCJP 1.4, SCMAD 1.0<br />SCWCD, SCBCD (in progress)
Chase Becicka
Greenhorn

Joined: Feb 16, 2004
Posts: 23
Okay I can see my JFrame now but I can't see my panels I created unless I resize my JFrame but I don't want my JFrame to be resizeable in the end. Should I just switch to a easier Layout Manager or is there an easy fix

what I am trying to get this to do is go gown vertically like this

Label TF
Label TF
Label TF

ect.


Heres the cod eupdated again
Craig Wood
Ranch Hand

Joined: Jan 14, 2004
Posts: 1535
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Won't Display
 
Similar Threads
Componet Allignment
FlowLayout Display Problems
Transforming Code
Please help me - accumulating scores!
NoClassDefFound error