942,504 Members | Top Members by Rank

Ad:
  • Java Discussion Thread
  • Unsolved
  • Views: 6507
  • Java RSS
Apr 13th, 2004
0

Help needed In creating application to make business cards

Expand Post »
Hi Everyone,

I am a student and I have been asked to make a program to create business cards. At the moment I have made a fully working application with file IO. The program basicly takes any input into the text fields and displays them on a business card template. Also it is necessary for the program to put a logo onto the business card by means of selection boxes. I already have written methods for drawing the logos, at the moment they are seperate applets. On my application I have included seletion boxes but at the moment they are tied to a String array so when the selection is made the strings: "Logo1", "Logo2", and "logo3" are displayed on the card rather than the Graphical logos drawn in the applets I have previously written. Can anyone suggest a way that I can tie the selection boxes to the logos so that they are displayed on the screen, Even if i have to cut and paste the methods into my new application code. I just need some help doing it.
Similar Threads
Reputation Points: 10
Solved Threads: 0
Newbie Poster
clobbasaurus is offline Offline
2 posts
since Apr 2004
Apr 13th, 2004
0

Re: Help needed In creating application to make business cards

Oh by the way here is the code i am using so far: Please can anyone help I have been sitting at the computer scratching my head all day. A forum really is my last resort so any help would be greatly appreciated.

import java.awt.*;
import java.awt.event.*;
import java.io.*;

public class BusinessCard extends Frame implements ActionListener, ItemListener {

private Panel p1 ,p2, p3, p4, p5, bigP;
private TextField nameField;
private TextField phoneNumberField;
private Choice companyChoice;
private Button display,saveButton;
private CheckboxGroup c;
private Checkbox logo1, logo2, logo3;
private Label errorLabel;
private int phoneNumbers ;
private String name = " ";
private String[] logoArray = {"Logo1","Logo2","Logo3"} ;
private String logo = logoArray[0];
private String[] companyArray = new String[8]; // = {"Microstar International","AGNEOVO","Toshiba","Sony","Seagate","Microsoft","LG","AMD"} ;
private String company = " ";
private Card myCard;

public static void main(String[] args) {
BusinessCard pd = new BusinessCard();
pd.setSize(500,350);
pd.setVisible(true);
}
public BusinessCard() {
enableEvents(AWTEvent.WINDOW_EVENT_MASK);
try {
BufferedReader in = new BufferedReader(new FileReader("company.txt"));
String str;
int i = 0;
while ((str = in.readLine()) != null) {
companyArray[i] = str;
i++;
}
in.close();
}
catch (IOException e) {
System.err.println("File Error: " + e.toString() );
System.exit(1);
}
setLayout(new BorderLayout());
setBackground( new Color(222,254,174));
myCard = new Card();

bigP= new Panel();
bigP.setLayout(new BorderLayout());
bigP.setBackground( new Color(86,113,248));
p1 = new Panel();
nameField=new TextField(10);
p1.add(new Label("Name: "));
p1.add(nameField);
bigP.add("West",p1);

p2 = new Panel();
phoneNumberField=new TextField(15);
p2.add(new Label("Phone Number: "));
p2.add(phoneNumberField);
bigP.add("Center",p2);

p3 = new Panel();
c = new CheckboxGroup();
p3.add(new Label("Select a Logo :"));
logo1 = new Checkbox("Logo1", c, true);
p3.add(logo1);
logo1.addItemListener(this);
logo2 = new Checkbox("Logo2", c, false);
p3.add(logo2);
logo2.addItemListener(this);
logo3 = new Checkbox("Logo3", c, false);
p3.add(logo3);
logo3.addItemListener(this);
bigP.add("South",p3);
p4 = new Panel();
companyChoice = new Choice();
for (int i=0; i<7 ; i++ )
{
companyChoice.addItem(companyArray[i]);
}
companyChoice.select(0);
companyChoice.addItemListener(this);
p4.add(new Label("Choose Your Company: "));
p4.add(companyChoice);

bigP.add("North",p4);
add("North",bigP);
p5 = new Panel();
p5.setLayout(new BorderLayout());
p5.setBackground( Color.BLUE);
display = new Button("Display");
saveButton = new Button("Save");
p5.add("East",display);
p5.add("West",saveButton);
display.addActionListener(this);
saveButton.addActionListener(this);
errorLabel = new Label( "... ");
errorLabel.setForeground(Color.RED);
p5.add("South", errorLabel);
add("South",p5);

}
public void itemStateChanged(ItemEvent e) {

if (logo1.getState() == true)
logo = logoArray[0];
else if (logo2.getState() == true)
logo = logoArray[1];
else
logo = logoArray[2];
// repaint();
}
public void actionPerformed(ActionEvent event) {
company = companyChoice.getSelectedItem();

if (event.getSource()==display){
try{
name=nameField.getText();
phoneNumbers=Integer.parseInt(phoneNumberField.getText());
myCard.setName(name);
myCard.setPhoneNumber(phoneNumbers);
myCard.setLogo(logo);
myCard.setCompany(company);
}

catch(Exception e) {

errorLabel.setText("Enter Numbers Only. No spaces or other Characters");
}
}
if (event.getSource() == saveButton ) {

try {
BufferedWriter out = new BufferedWriter(new FileWriter("cards.txt", true));
out.write( name + ", " + phoneNumbers + ", " + company );
out.newLine();
out.close();
}
catch (IOException e) {
System.err.println("File Error: " + e.toString() );
System.exit(1);
}
}
repaint();
}
public void paint (Graphics g) {
this.getGraphics().clearRect(120, 120, 200, 120);
myCard.presentCard(g);
}
public void processWindowEvent( WindowEvent e) {
super.processWindowEvent(e);
if (e.getID() == WindowEvent.WINDOW_CLOSING){
System.exit(0);
}

}
}
Reputation Points: 10
Solved Threads: 0
Newbie Poster
clobbasaurus is offline Offline
2 posts
since Apr 2004
Apr 13th, 2004
0

Re: Help needed In creating application to make business cards

instead of having the logos be drawn in the app. have the user draw it somewhere else and allow them to insert any image ontop of the template.
Reputation Points: 28
Solved Threads: 9
Posting Whiz in Training
BountyX is offline Offline
222 posts
since Mar 2004

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in Java Forum Timeline: I have some examples who would like to see some cool stuff
Next Thread in Java Forum Timeline: Word.doc upload using JSP





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC