Can anyone help me with this program?
I have to make program that asks the user for information that they would want on a business card. Then, I am supposed ot take that information that was gathered with a listener and display it on a second panel using graphicsstuff (such as g.drawString(VARIABLEHERE, int x, int y). I can get thepart of the program that would ask for the information, but I can't figure out where to go from there on how to display the information. If anyone could help I would be enternally gratefully. This assignment is due Friday morning at 9:00. Thanks!
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
public class PanelPractice extends JPanel
private static JButton insert;
private static JTextField nameField, positionField, areaField, telField, faxField, emailField, add1Field, add2Field, add3Field;
private static String nameText, positionText, areaText, telText, faxText, emailText, add1Text, add2Text, add3Text;
public static void main (String[] args)
//Makes two colored panels that are nested within a third.
JFrame frame = new JFrame ("Business Card");
frame.setDefaultCloseOperation (JFrame.EXIT_ON_CLOSE);
//Makes the first subpanel
JPanel subPanel1 = new JPanel();
JLabel nameLabel, positionLabel, areaLabel, telLabel, faxLabel, emailLabel, add1Label, add2Label, add3Label;
// Sets up the GUI
//Creates labels for the information questions
nameLabel = new JLabel ("Type the name you want on the card: ");
positionLabel = new JLabel ("Type the person's position: ");
areaLabel = new JLabel ("Type the person's area of business: ");
telLabel = new JLabel ("Type the person's telephone number: ");
faxLabel = new JLabel ("Type the person's fax number: ");
emailLabel = new JLabel ("Type the person's e-mail address: ");
add1Label = new JLabel ("Type the person's place of business: ");
add2Label = new JLabel ("Type the business' street address: ");
add3Label = new JLabel ("Type the business' city, state, and zip: ");
//Creates a JTextField to hold the person's name
nameField = new JTextField (10);
positionField = new JTextField (10);
areaField = new JTextField (10);
telField = new JTextField (10);
faxField = new JTextField (10);
emailField = new JTextField (10);
add1Field = new JTextField (10);
add2Field = new JTextField (10);
add3Field = new JTextField (10);
//add the nameLabel and nameField to the panel
subPanel1.add (nameLabel);
subPanel1.add (nameField);
//add the positionLabel and positionField to the panel
subPanel1.add (positionLabel);
subPanel1.add (positionField);
//add the areaLabel and areaField to the panel
subPanel1.add (areaLabel);
subPanel1.add (areaField);
//add the telLabel and telField to the panel
subPanel1.add (telLabel);
subPanel1.add (telField);
//add the faxLabel and faxField to the panel
subPanel1.add (faxLabel);
subPanel1.add (faxField);
//add the emailLabel and emailField to the panel
subPanel1.add (emailLabel);
subPanel1.add (emailField);
//add the add1Label and add1Field to the panel
subPanel1.add (add1Label);
subPanel1.add (add1Field);
//add the add2Label and add2Field to the panel
subPanel1.add (add2Label);
subPanel1.add (add2Field);
//add the add3Label and add3Field to the panel
subPanel1.add (add3Label);
subPanel1.add (add3Field);
//Creates a button to press to insert the information onto the card
insert = new JButton ("Insert Information!");
//Creates a Listener and makes it listen for the button to be pressed
insert.addActionListener (new ButtonListener());
//add the button to the panel
subPanel1.add (insert);
//set the size of the panel to the width and height constants
subPanel1.setPreferredSize (new Dimension (350, 300));
//set the color of the panel to whatever you choose
subPanel1.setBackground (Color.red);
//Makes the second subpanel
JPanel subPanel2 = new JPanel();
subPanel2.setPreferredSize (new Dimension(500,300));
subPanel2.setBackground (Color.blue);
//Makes the primary panel
JPanel primary = new JPanel();
primary.setBackground (Color.black);
primary.add (subPanel1);
primary.add (subPanel2);
frame.getContentPane().add(primary);
frame.pack();
frame.setVisible(true);
// Represents an action listener for the insert button.
private static class ButtonListener implements ActionListener
public void actionPerformed (ActionEvent event)
//get the text from the textfields
nameText = nameField.getText();
positionText = positionField.getText();
areaText = areaField.getText();
telText = telField.getText();
faxText = faxField.getText();
emailText = emailField.getText();
add1Text = add1Field.getText();
add2Text = add2Field.getText();
add3Text = add3Field.getText();
public static class CustomComponent extends JPanel
public void paintComponent(Graphics g)
super.paintComponent(g);
g.drawString(nameText, 5, 5);
}
Sorry about that...
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
public class PanelPractice extends JPanel
private static JButton insert;
private static JTextField nameField, positionField, areaField, telField, faxField, emailField, add1Field, add2Field, add3Field;
private static String nameText, positionText, areaText, telText, faxText, emailText, add1Text, add2Text, add3Text;
public static void main (String[] args)
//Makes two colored panels that are nested within a third.
JFrame frame = new JFrame ("Business Card");
frame.setDefaultCloseOperation (JFrame.EXIT_ON_CLOSE);
//Makes the first subpanel
JPanel subPanel1 = new JPanel();
JLabel nameLabel, positionLabel, areaLabel, telLabel, faxLabel, emailLabel, add1Label, add2Label, add3Label;
// Sets up the GUI
//Creates labels for the information questions
nameLabel = new JLabel ("Type the name you want on the card: ");
positionLabel = new JLabel ("Type the person's position: ");
areaLabel = new JLabel ("Type the person's area of business: ");
telLabel = new JLabel ("Type the person's telephone number: ");
faxLabel = new JLabel ("Type the person's fax number: ");
emailLabel = new JLabel ("Type the person's e-mail address: ");
add1Label = new JLabel ("Type the person's place of business: ");
add2Label = new JLabel ("Type the business' street address: ");
add3Label = new JLabel ("Type the business' city, state, and zip: ");
//Creates a JTextField to hold the person's name
nameField = new JTextField (10);
positionField = new JTextField (10);
areaField = new JTextField (10);
telField = new JTextField (10);
faxField = new JTextField (10);
emailField = new JTextField (10);
add1Field = new JTextField (10);
add2Field = new JTextField (10);
add3Field = new JTextField (10);
//add the nameLabel and nameField to the panel
subPanel1.add (nameLabel);
subPanel1.add (nameField);
//add the positionLabel and positionField to the panel
subPanel1.add (positionLabel);
subPanel1.add (positionField);
//add the areaLabel and areaField to the panel
subPanel1.add (areaLabel);
subPanel1.add (areaField);
//add the telLabel and telField to the panel
subPanel1.add (telLabel);
subPanel1.add (telField);
//add the faxLabel and faxField to the panel
subPanel1.add (faxLabel);
subPanel1.add (faxField);
//add the emailLabel and emailField to the panel
subPanel1.add (emailLabel);
subPanel1.add (emailField);
//add the add1Label and add1Field to the panel
subPanel1.add (add1Label);
subPanel1.add (add1Field);
//add the add2Label and add2Field to the panel
subPanel1.add (add2Label);
subPanel1.add (add2Field);
//add the add3Label and add3Field to the panel
subPanel1.add (add3Label);
subPanel1.add (add3Field);
//Creates a button to press to insert the information onto the card
insert = new JButton ("Insert Information!");
//Creates a Listener and makes it listen for the button to be pressed
insert.addActionListener (new ButtonListener());
//add the button to the panel
subPanel1.add (insert);
//set the size of the panel to the width and height constants
subPanel1.setPreferredSize (new Dimension (350, 300));
//set the color of the panel to whatever you choose
subPanel1.setBackground (Color.red);
//Makes the second subpanel
JPanel subPanel2 = new JPanel();
subPanel2.setPreferredSize (new Dimension(500,300));
subPanel2.setBackground (Color.blue);
//Makes the primary panel
JPanel primary = new JPanel();
primary.setBackground (Color.black);
primary.add (subPanel1);
primary.add (subPanel2);
frame.getContentPane().add(primary);
frame.pack();
frame.setVisible(true);
// Represents an action listener for the insert button.
private static class ButtonListener implements ActionListener
public void actionPerformed (ActionEvent event)
//get the text from the textfields
nameText = nameField.getText();
positionText = positionField.getText();
areaText = areaField.getText();
telText = telField.getText();
faxText = faxField.getText();
emailText = emailField.getText();
add1Text = add1Field.getText();
add2Text = add2Field.getText();
add3Text = add3Field.getText();
public static class CustomComponent extends JPanel
public void paintComponent(Graphics g)
super.paintComponent(g);
g.drawString(nameText, 5, 5);
} No..I'm not expecting someone to do it for me. I am having trouble figuring out what to do next. I cannot get anything to show up on the second panel...the part that displays the information that the listener gathered.
If I could figure out how to get one thing to show up...then I could probably do the rest...it's getting it started that I can't get.
Similar Messages
-
Can anyone help me with this program using the Scanner Class?
I have to write a program that asks for the speed of a vehicle (in miles-per-hour) and the number of hours it has traveled. It should use a loop to display the distance a vehicle has traveled for each hour of a time period specified by the user. Such as 1 hour will equal 40 miles traveled, 2 hours will equal 80, 3 hours will equal 120, etc. This is what I've come up with thus far. Any help is appreciated.
import java.util.Scanner;
public class DistanceTraveled
public static void main(String[] args)
int speed;
int hours;
int distance;
Scanner keyboard = new Scanner(System.in);
System.out.print("What is the speed of the vehicle in miles-per-hour?");
speed = keyboard.nextInt();
System.out.print("How many hours has the vehicle traveled for?");
hours = keyboard.nextInt();
distance = speed*hours;
while (speed < 0)
while (hours < 1)
System.out.println("Hour Distance Traveled");
System.out.println("------------------------");
System.out.println(hours + " " + distance);
}When you post code, wrap it in code tags. Highlight it and click the CODE button above the text input area.
You seem to be trying to reuse the speed and hours variables in your loop. That's probably a mistake at this point. Keep it simpler by defining a loop variable.
Also I don't see the need for two loops. You just want to show how far the vehicle has traveled for each one-hour increment, assuming constant speed, for the number of hours it has been traveling, right? So a single for loop should be sufficient. -
I am not able to Mobile Me email account to connect with iCloud or my Apple Mail program. Don't know if my settings are correct or not. Can anyone help me with this please?
http://support.apple.com/kb/HT5922
If you want to mirror your desktop, see:
http://support.apple.com/kb/HT5404
Regards. -
"It is formatted incorrectly, or is not a format that iBooks can open". Can anyone help me with this message of a book that I purchased on iBooks, read, highlighted in the book and now I can't open it anymore. Please help!!!
Mine does the same thing occasionally, is your phone jailbroken? Sometimes it will work if you delete the book and reinstall it or put your phone into airplane mode then turn it back off.
-
I can't find the 2G, 3G and LTE options after updating to iOS8.1, can anyone help me with this? I'm using iPhone5s
I have check on my service provider about the correct APN settings, but unfortunately doesnt work still..
-
I need to reinstall my operating system for 10.5 after seeing a file folder and question mark flashing on my start up screen. Can anyone help me with this?
Hello,
That means it can find the Hard Drive, or can't find the things needed for booting.
See if DU even sees it.
"Try Disk Utility
1. Insert the Mac OS X Install disc, then restart the computer while holding the C key.
2. When your computer finishes starting up from the disc, choose Disk Utility from the Installer menu at top of the screen. (In Mac OS X 10.4 or later, you must select your language first.)
*Important: Do not click Continue in the first screen of the Installer. If you do, you must restart from the disc again to access Disk Utility.*
3. Click the First Aid tab.
4. Select your Mac OS X volume.
5. Click Repair Disk, (not Repair Permissions). Disk Utility checks and repairs the disk."
http://docs.info.apple.com/article.html?artnum=106214
Then try a Safe Boot, (holding Shift key down at bootup), run Disk Utility in Applications>Utilities, then highlight your drive, click on Repair Permissions, reboot when it completes.
(Safe boot may stay on the gray radian for a long time, let it go, it's trying to repair the Hard Drive.) -
Hi can anyone help with this issue regarding my wireless magic mouse? When im on google chrome and scrolling down the page i always have youtube running in the background but the audio cuts/spits/pops can anyone help me with this?
The figures you mention only make sense on your intranet. Are you still using the same wireless router. The verizon one is somewhat limited as far as max wireless-n performace. For one thing it only has a 2.4 radio. I like many people who wanted wireless-n performance before they even added a wireless-n gigabit router, have my own handling my wireless-n network.
-
When my screen saver has been on a while, I have to use the cursor to "rub out" part of the screen saver to see my login section. Can anyone help me with this?
I don't have a solution for you, but just wanted to let you know I used to have the exact same problem. I resolved it (for the most part....about 90% of the time, anyway) by adjusting the screensaver and power settings to never let the computer go to sleep.
-
(The iPhone "Named" cannot be restored at this time because the iPhone software update server could not be contacted or is temporarily unavailable.)
can anyone help me with this issue, every time i try to restore it will come up like this error message.Restore the iPhone when connected to iTunes by cable.
Still the same TS1275?
Is your iPhone jailbroken?
Or
Has your computer ever been used to jailbrake or downgrade (Tinyumbrella) any iPhone? -
When typing the name of the contact I want to send a text message to, names from my contact list no longer pop up as suggestions. Can anyone help me with this?
There's always a way to reset the device jmn33! Thanks for keeping us in the loop. To process a full reset/restore on the device please visit http://vz.to/12TLCsR. Please keep us posted once this is completed, thanks!
MatthewS_VZW
Follow us on Twitter @VZWSUPPORT -
My search bar for my iTunes library no longer works. Also, the menu bar is no longer visible. Noticed this problem last Saturday. This might be an issue with my desktop, and not iTunes itself Can anyone help me with this?
Press Ctrl-B to toggle the menu bar on and off.
When you say that the "search bar for my iTunes library no longer works" can you be more specific? The operation of the search function has changed in iTunes 12, essentially having two very distinct modes:
when Search Entire Library is checked, entering a search string will generate a dropdown of all matching items within your whole library, from which multiple operations are available via context menus
when Search Entire Library is unchecked, entering a search string creates a filtered view of whatever your current focus is (e.g., if you're looking at a playlist the filter applies only to items in that playlist) with none of the dropdown options as in the first case -
I have updated to the latest version of iPhoto. But now iPhoto will not let me amend the preset text in the text boxes.
the text is highlighted for a nano second but it will not stay highlighted so that I can add my own text.
can anyone help me with this issue.
Many thanksYou might try using the add-on 'NoSquint' which allows numerous zoom options specific to each page you visit & keeps your settings - https://addons.mozilla.org/en-US/firefox/addon/nosquint/
If you want to go back to 3.6x, you will find it here:
http://www.mozilla.com/en-US/firefox/all-older.html
In most cases you can simply "upgrade" (meaning downgrade) directly from the installation. It would be a good idea to save your passwords & bookmarks just to be on the safe side. -
Mail on my Mac computer does not update when I update my mail on my iPhone and iPad. Can anyone help me with this? Is there a setting that I need to check?
All that you had to do was to sign into the old account in order to update those apps. What I mean is that you just needed to sign into that account in the store settings like I described and that should have worked. You didnt need to enter the credit card information again - you justed needed to use the old ID and password.
Anyway, I think the good news is that if everything else is OK with the new account, just download iBooks with the new ID - it's a free app so its not like you have to pay for it again. I'm not sure what the other App is that you are talking about - but if it is the Apple Store App - that is free as well.
Try this anyway, when you try to update iBooks, just use the old password if the old ID still pops up.
Did you try signing into the store settings with your new ID and see what happens with the updates then? -
I Want to buy diamonds for my tos game but it come out a message ask me to contact itune support. Can anyone help me with this? What should I do so that I can buy my diamonds?
You can contact iTunes support via this page and ask them why the message is appearing (on these forums we won't know why) : http://www.apple.com/support/itunes/contact/ - click on Contact iTunes Store Support on the right-hand side of the page, then try selecting Purchases, Billing & Redemption
-
I can't download iOS 7 on my iPad 3. I says my software is up to date (6.1.3). Can anyone help me with this?
May just be the update server acting glitchy due all the people slamming it right now. I'd give it 24 hrs, and if it's still doing it, check back in here and we'll see if we can't figure it out.
= L.I.
Maybe you are looking for
-
How to calculate running balance
can we calculate running balance in discoverer 3.1.36 thanx in anticipation
-
I am receiving an Invalid column name SQLException. I initially thought it was a problem with the computed fields, but was after making the usual changes to the model implementation the exception is still occurring. I can run the SQL statement in SQL
-
Camera raw vs. ps?
Why would you color correct non raw related files in camera raw vs. ps? Why is camera raw not just a part of ps? Thanks.
-
my internet page is only showing like half the page the bottom half is white and the top is my website but it aint the whole page. == This happened == Every time Firefox opened == a week ago
-
Why am I unable to open many applications on my macbook pro?
Why am I unable to open many applications on my macbook pro?Uu