hello can you help me please... i have a button print and i dont know how to make the code that will print all my data in my database....please help me how to make this print code ..hoping for your positive responds.

Recommended Answers

All 6 Replies

sending to the printer thanks for the reply..please help me on this thanks in advance hoping for your positive responds

check out the Java Printing API.

hello thanks for the reply...can you give me the link for this thanks in advance....

ahm if you can help me to make the code for printing here's my program..please help me how to print my data to the printer..hoping for your positive responds.

import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.event.*;


public class Maintenance extends JDialog
{
private JLabel idnoLbl, dateHiredLbl, lNameLbl, fNameLbl, miLbl;
private JLabel genLbl, posLbl;
private JTextField idnoFld, dateHiredFld, lNameFld, fNameFld, miFld;
private JTextField posFld,salFld;
private JRadioButton maleRBtn, femaleRBtn, singleRBtn, marriedRBtn, widowRBtn;
private JButton addBtn, editBtn, searchBtn, delBtn, clearBtn, exitBtn;
private JTextArea area;
private JPanel p1, p2, p3, p4, p5, panel;
private ButtonGroup bg1, bg2;
protected DBConn conn;// = new DBConn();


public Maintenance()
{
//super("Maintenance");
Container c = getContentPane();
c.setLayout(new GridLayout(5,1));
setSize(380, 455);
setModal(true);
setTitle("Maintenance");
// Get the size of the screen
Dimension dim = Toolkit.getDefaultToolkit().getScreenSize();


// Determine the new location of the window
int w = getSize().width;
int h = getSize().height;
int x = (dim.width-w)/2;
int y = (dim.height-h)/2;


// Move the window
setLocation(x, y);



p1 = new JPanel();
p1.setLayout(new FlowLayout());


idnoLbl = new JLabel("ID Number:");
idnoFld = new JTextField(10);
dateHiredLbl = new JLabel("Date Hired:");
dateHiredFld = new JTextField(10);
lNameFld = new JTextField(10);
fNameFld = new JTextField(10);
miFld = new JTextField(10);
lNameLbl = new JLabel("   Last Name                ");
fNameLbl = new JLabel("First Name");
miLbl = new JLabel("                 Middle Initial");


p1.add(idnoLbl);
p1.add(idnoFld);
p1.add(dateHiredLbl);
p1.add(dateHiredFld);
p1.add(lNameFld);
p1.add(fNameFld);
p1.add(miFld);
p1.add(lNameLbl);
p1.add(fNameLbl);
p1.add(miLbl);
c.add(p1);// add first panel


JPanel p2 = new JPanel();
p2.setLayout(new FlowLayout());


posFld = new JTextField(10);
genLbl = new JLabel("                             Gender");
maleRBtn = new JRadioButton("Male");
femaleRBtn = new JRadioButton("Female");
bg1 = new ButtonGroup();
bg1.add(maleRBtn);
bg1.add(femaleRBtn);


p2.add(posFld);
p2.add(genLbl);
p2.add(maleRBtn);
p2.add(new JLabel("            "));
p2.add(new JLabel("Position"));
p2.add(new JLabel("                                                        "));
p2.add(femaleRBtn);
bg1.add(maleRBtn);
bg1.add(femaleRBtn);
c.add(p2);//add second panel


p3 = new JPanel();
p3.setLayout(new FlowLayout());


salFld = new JTextField(10);
singleRBtn = new JRadioButton("Single");
marriedRBtn = new JRadioButton("Married");
widowRBtn = new JRadioButton("Widow");


p3.add(salFld);
p3.add(new JLabel("                                     Civil     "));
p3.add(singleRBtn);
p3.add(new JLabel("            Salary"));
p3.add(new JLabel("                                                      Status"));
p3.add(marriedRBtn);
p3.add(new JLabel("                                                                                            "));
p3.add(widowRBtn);
bg2 = new ButtonGroup();
bg2.add(singleRBtn);
bg2.add(marriedRBtn);
bg2.add(widowRBtn);


c.add(p3);//add third panel


p4 = new JPanel();
p4.setLayout(new FlowLayout());
p4.setBorder(BorderFactory.createEtchedBorder(0));


addBtn = new JButton("      ADD      ");
addBtn.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent e)
{
conn = new DBConn();
try{
String id = idnoFld.getText();
String lname = lNameFld.getText();
String fname = fNameFld.getText();
String mi = miFld.getText();
String gender;
if(maleRBtn.isSelected())
gender = "Male";
else
gender = "Female";
String status;
if(singleRBtn.isSelected())
status = "Sinlge";
else if(marriedRBtn.isSelected())
status = "Married";
else
{
if(maleRBtn.isSelected())
status = "Widow";
else
status = "Widower";
}


String position = posFld.getText();
String salary = salFld.getText();
String hired = dateHiredFld.getText();
conn.add(id, lname, fname, mi, gender, status, position, salary, hired);
idnoFld.setText("");
lNameFld.setText("");
fNameFld.setText("");
miFld.setText("");
maleRBtn.setSelected(true);
singleRBtn.setSelected(true);
posFld.setText("");
salFld.setText("");
dateHiredFld.setText("");
}catch(Exception ex){}
}
}
);



editBtn = new JButton("       EDIT       ");
editBtn.addActionListener(
new ActionListener()
{
public void actionPerformed(ActionEvent e)
{
conn = new DBConn();


try{
String gender;
if(maleRBtn.isSelected())
gender = "Male";
else
gender = "Female";


String status;
if(singleRBtn.isSelected())
status = "Sinlge";
else if(marriedRBtn.isSelected())
status = "Married";
else
{
if(maleRBtn.isSelected())
status = "Widow";
else
status = "Widower";
}
conn.edit(idnoFld.getText(), lNameFld.getText(), fNameFld.getText(),
miFld.getText(), gender, status, posFld.getText(), salFld.getText(), dateHiredFld.getText());
idnoFld.setText("");
lNameFld.setText("");
fNameFld.setText("");
miFld.setText("");
maleRBtn.setSelected(true);
singleRBtn.setSelected(true);
posFld.setText("");
salFld.setText("");
dateHiredFld.setText("");
}catch(Exception ex){}
}
}
);



searchBtn = new JButton("  SEARCH  ");
searchBtn.addActionListener(
new ActionListener()
{
public void actionPerformed(ActionEvent e)
{
conn = new DBConn();
try{
String id = idnoFld.getText();
conn.search(id);


String hired = conn.hired.toString();
String lname = conn.lname.toString();
String fname = conn.fname.toString();
String mi = conn.mi.toString();
String gender = conn.gender.toString();
String status = conn.status.toString();
String position = conn.position.toString();
String salary = conn.salary.toString();



dateHiredFld.setText(hired);
lNameFld.setText(lname);
fNameFld.setText(fname);
miFld.setText(mi);
if(gender.equals("Male"))
maleRBtn.setSelected(true);
else
femaleRBtn.setSelected(true);


if(status.equals("Single"))
singleRBtn.setSelected(true);
else if(status.equals("Married"))
marriedRBtn.setSelected(true);
else
widowRBtn.setSelected(true);
posFld.setText(position);
salFld.setText(salary);


}catch(Exception ex){}
}
}
);



delBtn = new JButton("     DELETE     ");
delBtn.addActionListener(
new ActionListener()
{
public void actionPerformed(ActionEvent e)
{
conn = new DBConn();
try{
String id = idnoFld.getText();
conn.delete(id);
idnoFld.setText("");
lNameFld.setText("");
fNameFld.setText("");
miFld.setText("");
maleRBtn.setSelected(true);
singleRBtn.setSelected(true);
posFld.setText("");
salFld.setText("");
dateHiredFld.setText("");


}catch(Exception ex){}
}
}
);



clearBtn = new JButton("       CLEAR       ");
clearBtn.addActionListener(
new ActionListener()
{
public void actionPerformed(ActionEvent e)
{
idnoFld.setText("");
lNameFld.setText("");
fNameFld.setText("");
miFld.setText("");
maleRBtn.setSelected(true);
singleRBtn.setSelected(true);
posFld.setText("");
salFld.setText("");
dateHiredFld.setText("");
}
}
);



exitBtn = new JButton("       EXIT       ");
exitBtn.addActionListener(
new ActionListener()
{
public void actionPerformed(ActionEvent e)
{
setVisible(false);
}
}
);


p4.add(addBtn);
p4.add(editBtn);
p4.add(searchBtn);
p4.add(delBtn);
p4.add(clearBtn);
p4.add(exitBtn);



c.add(p4); // add fourth panel


p5 = new JPanel();
p5.setLayout(new FlowLayout());


area = new JTextArea(4, 33);
area.setForeground(Color.red);
JScrollPane scroll = new JScrollPane(area);
p5.add(scroll);


c.add(p5); //add fifth panel



setResizable(false);
setVisible(true);
}


public static void main(String[] args)
{
new Maintenance();
}
}
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.