Search...
FAQs
Subscribe
Pie
FAQs
Recent topics
Flagged topics
Hot topics
Best topics
Search...
Search within Applets
Search Coderanch
Advance search
Google search
Register / Login
Win a copy of
Building Green Software: A Sustainable Approach to Software Development and Operations
this week in the
Agile/Processes
forum!
Post Reply
Bookmark Topic
Watch Topic
New Topic
programming forums
Java
Mobile
Certification
Databases
Caching
Books
Engineering
Micro Controllers
OS
Languages
Paradigms
IDEs
Build Tools
Frameworks
Application Servers
Open Source
This Site
Careers
Other
Pie Elite
all forums
this forum made possible by our volunteer staff, including ...
Marshals:
Tim Cooke
Campbell Ritchie
paul wheaton
Jeanne Boyarsky
Ron McLeod
Sheriffs:
Paul Clapham
Devaka Cooray
Saloon Keepers:
Tim Holloway
Carey Brown
Piet Souris
Bartenders:
Forum:
Applets
Frames
Erick Heberling
Greenhorn
Posts: 13
posted 19 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
Is there a way to call a panel from another class into a Jframe?
I will post the code below. I am wanting to use the panel in the keyboardButton class in my frame class.
Frame class:
package FinalProject; import FinalProject.keyboardButtonClass; import java.awt.BorderLayout; import java.awt.Container; import java.awt.Dimension; import java.awt.GridLayout; import java.awt.Toolkit; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import javax.swing.JButton; import javax.swing.JFrame; import javax.swing.JLabel; import javax.swing.JPanel; import javax.swing.JTextField; //import javax.swing.JTextField; //import FinalProject.keyboardButtonClass; public class frameClassII extends JFrame implements ActionListener { private JPanel p1; private JLabel lblAcctField; private JTextField numberAcctField; private JLabel lblTransField; private JTextField numberTransField; private JButton btnWithdrawal; private JButton btnDeposit; public frameClassII() { keyboardButtonClass keyboardbutton = new keyboardButtonClass(); Container container = this.getContentPane(); JPanel p1 = new JPanel(); p1.setLayout(new BorderLayout()); container.add(p1); JPanel p6 = new JPanel(); p1.add(p6, BorderLayout.EAST); JPanel p2 = new JPanel(); p2.setLayout(new BorderLayout()); //p1.add(p2, BorderLayout.CENTER); p1.add(p2, BorderLayout.EAST); JPanel p3= new JPanel(); p3.setLayout(new GridLayout(2, 1)); p3.setSize(50,50); p2.add(p3, BorderLayout.NORTH); lblAcctField = new JLabel("Account Balance:"); numberAcctField = new JTextField("", 23); p3.add(lblAcctField); p3.add(numberAcctField); numberAcctField.setEditable(false); numberAcctField.addActionListener(this); JPanel p4 = new JPanel(); p4.setLayout(new GridLayout(2, 1)); p4.setSize(50,50); p2.add(p4, BorderLayout.CENTER); lblTransField = new JLabel("Transaction Amount:"); numberTransField = new JTextField("", 23); p4.add(lblTransField); p4.add(numberTransField); numberTransField.setEditable(false); numberTransField.addActionListener(this); JPanel p5 = new JPanel(); p5.setLayout(new GridLayout(1, 1)); p5.setSize(50,50); p2.add(p5, BorderLayout.SOUTH); btnWithdrawal = new JButton("Withdraw"); btnDeposit = new JButton("Deposit"); p5.add(btnWithdrawal); btnWithdrawal.addActionListener(this); p5.add(btnDeposit); btnDeposit.addActionListener(this); } public void actionPerformed(ActionEvent ae) { } public static void main(String[] args) { frameClassII mainFrame = new frameClassII(); mainFrame.setTitle("ATM"); mainFrame.setSize(600, 400); mainFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize(); Dimension frameSize = mainFrame.getSize(); int xLoc = (screenSize.width - frameSize.width) / 2; int yLoc = (screenSize.height - frameSize.height) / 2; mainFrame.setLocation(xLoc, yLoc); mainFrame.setVisible(true); } }
keyboardButtonClass:
import javax.swing.JFrame; import java.awt.Toolkit; import java.awt.Dimension; import javax.swing.JButton; import java.awt.BorderLayout; import java.awt.GridLayout; import java.awt.Container; import javax.swing.JPanel; public class keyboardButtonClass extends JFrame { public keyboardButtonClass () { // Get the content pane (container) of this JFrame Container container = this.getContentPane(); // Set the JFrame's container's LayoutManager to BorderLayout // with the horizontal and vertical gaps each set to 5 container.setLayout(new BorderLayout(5, 5)); // Create a JPanel with the LayoutManager set to a GridLayout // with 4 rows and 3 columns and 5 space gaps between components JPanel buttonPanel = new JPanel(new GridLayout (4, 3, 5, 5)); // Add the 12 phone buttons to the JPanel for (int i = 1; i <= 9; i++) { buttonPanel.add(new JButton("" + i)); } buttonPanel.add(new JButton("0")); buttonPanel.add(new JButton(".")); buttonPanel.add(new JButton("Clear")); // Add the Key Pad button panel to the center part of the frame container.add(buttonPanel, BorderLayout.CENTER); } public static void main(String[] args) { // Instantiate a JFrame object keyboardButtonClass keyboardFrame = new keyboardButtonClass(); // Set the title of the frame keyboardFrame.setTitle("ATM"); // Set the initial size of the frame keyboardFrame.setSize(300,350); // Set the fram to exit when it is closed keyboardFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); // Set the frame to be visible keyboardFrame.setVisible(true); } }
reply
reply
Bookmark Topic
Watch Topic
New Topic
Boost this thread!
Similar Threads
Exception in thread "main" java.lang.IllegalArgumentException: illegal component position
Adding Record Problem in JDBC ?
Combobox Help
JPanels with different content should have the same size
run time error
More...