Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Won't Display

 
Chase Becicka
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 524
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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...
 
Chase Becicka
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 1535
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic