| | |
Help needed In creating application to make business cards
Please support our Java advertiser: Programming Forums - DaniWeb Sister Site
![]() |
•
•
Join Date: Apr 2004
Posts: 2
Reputation:
Solved Threads: 0
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.
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.
•
•
Join Date: Apr 2004
Posts: 2
Reputation:
Solved Threads: 0
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);
}
}
}
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);
}
}
}
![]() |
Similar Threads
- need help creating a "stack" of cards (C++)
- How to create a Form application to make phone call on pocket pc (VB.NET)
Other Threads in the Java Forum
- Previous Thread: I have some examples who would like to see some cool stuff
- Next Thread: Word.doc upload using JSP
| Thread Tools | Search this Thread |
-xlint actionlistener android api applet application array arrays automation binary blackberry block bluetooth character chat class classes client code component consumer database desktop developmenthelp draw eclipse error event exception fractal ftp game givemetehcodez graphics gui html ide image input integer j2me j2seprojects java javac javaee javaprojects jmf jni jpanel julia lego linked linux list loop loops mac map method methods mobile netbeans newbie notdisplaying number online oracle page print printf problem program programming project properties recursion researchinmotion rotatetext rsa scanner screen server set singleton size sms sort sql string swing template textfields threads time title tree tutorial-sample update windows working





