Latest Tutorials| Questions and Answers|Ask Questions?|Site Map



Home Answers Viewqa Java-Beginners Java Print the all components
Login         

View Questions and Answers by Category

Advertisements


 
Have Programming Question? Ask it here!
 
 
 


Pushpa Sheela
Java Print the all components
0 Answer(s)      4 years and 2 months ago
Posted in : Java Beginners


This is my code. Please tell me the solutions

import javax.swing.table.*;

import javax.swing.*; import java.util.*; import java.awt.*; import java.awt.event.*; import java.awt.print.*; import java.awt.geom.*; import java.util.Calendar;

public class Salary_report extends JFrame implements ActionListener {

Vector data;
JTable table;
JLabel banner;  
ImageIcon images;
Container c;
Employee_report f1;
JButton print;
String s,days,basic,pf,hra,esi,bonus,advance,allowance,loan,incentive,dother,da,eother,gross,ded,net,leave;
double ge,td,np,l,l1;
public Salary_report(Employee_report f1)
{
    c=getContentPane();
c.setLayout(null);
setResizable(false);
setTitle("Employee Salary Report");
setBounds(250,50,700,750);

WindowShow.setNativeLookAndFeel();

s=f1.ename.getSelectedItem().toString();
basic=f1.txtbsalary.getText();
pf=f1.txtpf.getText();
hra=f1.txthra.getText();
esi=f1.txtesi.getText();
bonus=f1.txtbonus.getText();
advance=f1.txtadv.getText();
allowance=f1.txtsall.getText();
loan=f1.txtploan.getText();
incentive=f1.txtinc.getText();
dother=f1.txtoth.getText();
da=f1.txtda.getText();
eother=f1.txtoth1.getText();
l=Double.parseDouble(f1.txtleave.getText());
if(l<=1)
{
    leave="0";
}   
else
{
    Calendar calendar = Calendar.getInstance();
        int year = calendar.get(Calendar.YEAR);
        int month = calendar.get(Calendar.MONTH - 1);
        int date = 1;
        calendar.set(year, month, date);
        int day = calendar.getActualMaximum(Calendar.DAY_OF_MONTH);
        l1=(Double.parseDouble(basic)/day)*(l-1);
    leave=Double.toString(Math.round(l1));  
    days=Integer.toString(day);
}

ge=Double.parseDouble(basic)+Double.parseDouble(hra)+Double.parseDouble(bonus)+Double.parseDouble(allowance)+Double.parseDouble(incentive)+Double.parseDouble(da)+Double.parseDou

ble(eother); gross=Double.toString(ge); td=Double.parseDouble(pf)+Double.parseDouble(esi)+Double.parseDouble(advance)+Double.parseDouble(loan)+Double.parseDouble(dother)+Double.parseDouble(leave); ded=Double.toString(td); np=ge-td; net=Double.toString(np);

data = createData();
print=new JButton("Print");
print.setBounds(300,550,100,20);
c.add(print);
print.addActionListener(this);

SplitCellTableModel model = new SplitCellTableModel();
    table = new JTable(model);
    table.getColumnModel().getColumn(0).setCellEditor(new SplitTableCellEditor());
    table.getColumnModel().getColumn(1).setCellEditor(new SplitTableCellEditor());
    table.getColumnModel().getColumn(0).setCellRenderer(new SplitTableCellRenderer());
    table.getColumnModel().getColumn(1).setCellRenderer(new SplitTableCellRenderer());

    JScrollPane scroller = new JScrollPane(table);

    if(f1.cname.getSelectedItem().toString().equals("Teamwork Architecture"))
        images=new ImageIcon("TWA.jpg");
else if(f1.cname.getSelectedItem().toString().equals("Teamwork Techno Solutions"))
        images=new ImageIcon("TWT.jpg");
banner=new JLabel();
banner.setIcon(images);
banner.setBounds(60,50,600,150);
c.add(banner,BorderLayout.NORTH);


scroller.setBounds(60,250,600,260);
c.add(scroller);    
}

public void actionPerformed(ActionEvent ae)
{
    String str=ae.getActionCommand();
    if(str.equalsIgnoreCase("Print"))
    {   
        print.setVisible(false);
        PrintableDocument.printComponent(this);
    }
} 
public Vector createData()
{
    Vector result = new Vector();
Vector rec = new Vector();
    Object[] value = new Object[] {"Employee Name",s};
    rec.add(value);
    value = new Object[] {"Total Days",days};
    rec.add(value);
    result.add(rec);

    rec = new Vector();
    value = new Object[] {"", ""};
    rec.add(value);
value = new Object[] {"", ""};
    rec.add(value);
    result.add(rec);

rec = new Vector();
    value = new Object[] {"Earnings", ""};
    rec.add(value);
    value = new Object[] {"Deductions", ""};
    rec.add(value);
    result.add(rec);


rec = new Vector();
    value = new Object[] {"", ""};
    rec.add(value);                         
    rec.add(value);
    result.add(rec);

rec = new Vector();
    value = new Object[] {"Basic",basic};
    rec.add(value);
    value = new Object[] {"PF",pf};
    rec.add(value);
    result.add(rec);


rec = new Vector();
    value = new Object[] {"HRA",hra};
    rec.add(value);
    value = new Object[] {"ESI",esi};
    rec.add(value);
    result.add(rec);

rec = new Vector();
    value = new Object[] {"Bonus",bonus};
    rec.add(value);
    value = new Object[] {"Salary Advance",advance};
    rec.add(value);
    result.add(rec);


rec = new Vector();
    value = new Object[] {"Special Allowance",allowance};
    rec.add(value);
    value = new Object[] {"Personal Loan",loan};
    rec.add(value);
    result.add(rec);


rec = new Vector();
    value = new Object[] {"Incentive",incentive};
    rec.add(value);
value = new Object[] {"Others",dother};
    rec.add(value);
    result.add(rec);

rec = new Vector();
    value = new Object[] {"DA",da};
    rec.add(value);
value = new Object[] {"Leave",leave};
    rec.add(value);
    result.add(rec);

rec = new Vector();
    value = new Object[] {"Others",eother};
    rec.add(value);
value = new Object[] {"", ""};
    rec.add(value);
    result.add(rec);

rec = new Vector();
    value = new Object[] {"", ""};
    rec.add(value);
value = new Object[] {"", ""};
    rec.add(value);
    result.add(rec);

    rec = new Vector();
    value = new Object[] {"Gross Earnings(A)",gross};
    rec.add(value);
value = new Object[] {"Total Deductions(B)",ded};
    rec.add(value);
    result.add(rec);

rec = new Vector();
    value = new Object[] {"Net Pay (A)-(B)",net};
    rec.add(value);
value = new Object[] {"", ""};
    rec.add(value);
    result.add(rec);
    return result;
}

public class SplitCellTableModel extends DefaultTableModel { public SplitCellTableModel() { }

public int getRowCount()
{
    return data.size();
}

public int getColumnCount()
{
    return 2;
}

public String getColumnName(int col)
{
    if (col == 0)
        return " ";
    else
        return "Date";
}

public Object getValueAt(int row, int col)
{
    Vector rec = (Vector)data.get(row);
    return rec.get(col);
}

public Vector getDataVector()
{
    return data;
}

public boolean isCellEditable(int row, int col)
{
    return false;
}

public void setValueAt(Object value, int row, int col)
{
    Vector rec = (Vector)data.get(row);
    rec.setElementAt(value, col);
}

}

public class SplitTableCellEditor extends AbstractCellEditor implements TableCellEditor { JPanel editingPanel; JTextField leftTextField; JTextField rightTextField;

public SplitTableCellEditor()
{
    super();
    editingPanel = new JPanel();
    editingPanel.setLayout(new GridLayout(1, 2));
    leftTextField = new JTextField();
    editingPanel.add(leftTextField);
    rightTextField = new JTextField();
    editingPanel.add(rightTextField);
}

public Component getTableCellEditorComponent(JTable table, Object value, boolean isSelected, int rowIndex, int colIndex)
{
    Object[] splitVal = (Object[])value; // cast to array of Object
    if (splitVal != null)
    {
        String leftStr = (String)splitVal[0];
        String rightStr = (String)splitVal[1];
        leftTextField.setText(leftStr == null ? "" : leftStr);
        rightTextField.setText(rightStr == null ? "" : rightStr);
    }
    else
    {
        leftTextField.setText("");
        rightTextField.setText("");
    }
    return editingPanel;
}

public Object getCellEditorValue()
{
    Object[] value = new Object[] {leftTextField.getText(), rightTextField.getText()};
    return value;
}

}

public class SplitTableCellRenderer implements TableCellRenderer { JPanel rendererPanel; JLabel leftLabel; JLabel rightLabel;

public SplitTableCellRenderer()
{
    super();

    rendererPanel = new JPanel();
    rendererPanel.setLayout(new GridLayout(1, 2));
    leftLabel = new JLabel("Adfasdf");
    leftLabel.setOpaque(true);
    leftLabel.setBackground(Color.white);
    rendererPanel.add(leftLabel);
    rightLabel = new JLabel("adsfsdf");
    rightLabel.setOpaque(true);
    rightLabel.setBackground(Color.white);
    rendererPanel.add(rightLabel);
}

public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int col)
{
    Object[] splitVal = (Object[])value; // cast to array of Object
    if (splitVal != null)
    {
        String leftStr = (String)splitVal[0];
        String rightStr = (String)splitVal[1];
        leftLabel.setText(leftStr == null ? "" : leftStr);
        rightLabel.setText(rightStr == null ? "" : rightStr);
    }
    else
    {
        leftLabel.setText("");
        rightLabel.setText("");
    }
    return rendererPanel;
}

}

}

If i click print button then my current window is print in a paper.

The paper contain only half of the output. But i want full screen output.

Please tell me the solutions


Advertisement
View Answers

Related Tutorials/Questions & Answers:
Java Print the all components
Java Print the all components  This is my code. Please tell me...; ImageIcon images; Container c; Employee_report f1; JButton print; String s,days...(td); np=ge-td; net=Double.toString(np); data = createData(); print=new
how to print all colors using awt
how to print all colors using awt  how to print all colors using awt
Advertisements
how to print all possible combination that sum to zero??
how to print all possible combination that sum to zero??  ?.... Print all possible combinations that sum to zero Example Enter a num : 7 1... each of the digits so that the resultant sum is zero. Print all posible
what are the components of java platform ?
what are the components of java platform ?  what are the components of java platform ? plz if any1 perfectly know help me to override my conflicts.plz explain briefly
How to print this in java?
How to print pattern in Java?  How to print a particular pattern in Java...;  How to print this in java
print
print  How to print JFrame All Componant?   Please visit the following link: http://www.roseindia.net/java/example/java/swing/Print.shtml
Print Form - Java Beginners
Print Form  Hello Sir I have Created Admission Form when user fills data and submit that data to access database,then when i Click on PRINT Button I want to get Print of that forms Contents,How I can Do it with JAVA SWING,plz
Java Print Dialog
Java Print Dialog  Using java.awt.print.PrinterJob and javax.print.attribute.PrintRequestAttributeSet. I call .printDialog(ps) and the standard print dialog is displayed with options preset to my chosen attributes. Now I can
print rectangle pattern in java
print rectangle pattern in java  * * * * * * * how to generate this pattern in java??   Hi friend try this code may this will helpful for you public class PrintRectangle { public static void main
java awt components - Java Beginners
java awt components  how to make the the button being active at a time..? ie two or more buttons gets activated by click at a time
print a rectangle - Java Beginners
print a rectangle  how do I print a rectangleof stars in java using simple while loop?Assuming that the length n width of the rectangle is given.  Hi friend, I am sending running code. import java.io.
how to print - Java Beginners
how to print  how to print something on console without using System.out.print() method ?  Hi Friend, You can use PrintWriter to write anything on the console. import java.io.*; public class Print{ public static
Simplest way to print an array in Java
Simplest way to print an array in Java  Simplest way to print an array in Java
Create Layout Components in a Grid in Java
Create Layout Components in a Grid in Java   ... layout components with the help of grid in Java Swing. The grid layout provides... is the vertical gap between components. This constructor takes all the integer value
Reading Files and Print - Java Beginners
the Particular name "School A" and print all contents in the file(s). I give... where more than one student are from the same school it should print all...Reading Files and Print  Hey Guys, I'm a beginner to java and I
How to print the following pattern in java?
How to print the following pattern in java?  How to print the following pattern in java? he he is he is going he is going in   import java.io.*; class StringPattern { public static void main(String[] args
Print in a long paper - Java Beginners
Print in a long paper  how to print text in long paper?? each print text, printer stops. not continue until the paper print out. Thanks
I want to know the all possible syntax for EL code to print the first element of an array.
I want to know the all possible syntax for EL code to print the first element of an array.  Which is the correct EL codes syntax to print the first element of an array named employeeArray. ${employeeArray["0"]} or ${employeeArray
Components
Components in Flex4 is the simple extension of the components of Flex3. In this section, you will learns different types of spark components to be used in Flex4. Here is the list of spark components
Print
Print  In system.out.println,what meant ln..?   System: It is a class made available by Java to let you manipulate various operating system... into the stream and, as opposed to print() method, gets you to the new line after the text
accept sentence from user and print all word starts with vowel and end with consonent
accept sentence from user and print all word starts with vowel and end with consonent  Write a program to accept a sentence. Print all the words that starts with vowel and end with a consonant. e.g. input by user "the purpose
How to pretty print XML from Java?
How to pretty print XML from Java?  How to pretty print XML from Java
WAP in java to print the series 1*2*3
WAP in java to print the series 1*2*3  WAP in java to print the series 123
hi all - Java Beginners
hi all  hi, i need interview questions of the java asap can u please sendme to my mail   Hi, Hope you didnt have this eBook. You can download this at thislink... http://www.4shared.com/file/45195248/1f297b96
print only Form Fillup Contents through Text File - Java Beginners
print only Form Fillup Contents through Text File   Hello Sir ,I have Designed Employee Details Form using java swing components Now i want to print contents which is filled by employee,How i can Print it,and also i want print
how to print from right to left in java????
how to print from right to left in java????   can anyone pls tell how to print from right to left in java
Java AWT Components
Java AWT Components      ... components available in the Java AWT package for developing user interface for your program. Following some components of Java AWT are explained :  Labels
AWT Components
AWT Components       The class component is extended by all the AWT components. More of the codes can be put to this class to design lot of AWT components. Most of the AWT
Print Screen Using Java Swing
Print Screen Using Java Swing       In this section, you will learn how to print in java swing. The printable that is passed to setPrintable must have a print method
Java replace all non alphanumeric
Java replace all non alphanumeric  Hi, In Java how to replace all non alphanumeric characters with blank? Share me the best code for java replace all non alphanumeric. Thanks   Hi, You can use the replaceAll
Java Programming Implement a virtual print queue
Java Programming Implement a virtual print queue  Implement a virtual print queue. A single print queue is servicing a single printer. Print... records: q,3,10 is a q type record which indicates that a print job, # 3, shall
Advertisements
 

 

 

DMCA.com