dcsimg
August 19, 2018
Hot Topics:

User Code: jPrn

  • February 27, 2002
  • By S. Balasubramanian
  • Send Email »
  • More Articles »

How many Java developers know there is a class called 'printJob' in the AWT package? It's a very useful class that is used to print a file via Java. By using this class, I developed my own piece of software for printing a text file.

JPrn is only used to print text files (*.txt, *. java, *.c, etc.). Please, acquiesce this Achilles.

In future enhancements, I plan to support all files.

JPrn File Infrastructure

There are five files in the download, namely BaluDocPrn.java, jPrn.java, balu.jpg, map.jpg, and this one (jPrnReadme.txt).

How to Run

Step 1: First compile BaluDocPrn.java
Step 2: Then compile jPrn.java
Step 3: Finally, run jPrn.java

jPrn

*/


//Program Starts


import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import java.io.*;
import java.util.*;
import java.text.*;

public class jPrn extends JFrame implements Runnable
{
//public static String user;
ImageIcon i1,i2;
JLabel l1,l2,l3,l4,l5;
JTextField t1,t2,t3,t6,t7,t8;
TextField t4,t5;
//JComboBox j6,j7,j8;
JButton b;
JButton b1,b2,b3,b4,b5;
Label h1,h2;
Thread th1;

GridBagConstraints gc;
GridBagLayout gb;
Frame frm=this;

jPrn()
{
super("JPRN- A Text Printing S/W- Developed By S.Balasubramanian.");
this.setCursor(Frame.HAND_CURSOR);
gb=new GridBagLayout();
gc=new GridBagConstraints();
getContentPane().setLayout(gb);
getContentPane().setBackground(Color.pink);
gc.gridx=0;
gc.gridy=0;
gc.gridwidth=1;

i2=new ImageIcon("map.jpg");
b4=new JButton(i2);
b4.setBackground(Color.pink);
gc.insets=new Insets(0,0,350,400);
getContentPane().add(b4,gc); 

l1=new JLabel("File Name : ");
gc.insets=new Insets(0,0,300,-100);
getContentPane().add(l1,gc); 


t1= new JTextField(20);
gc.insets=new Insets(0,0,300,-415);
getContentPane().add(t1,gc); 


b1=new JButton("Browse");
b1.setToolTipText("Browse");
b1.setMnemonic('b');
gc.insets=new Insets(0,0,200,-275);
getContentPane().add(b1,gc); 

b=new JButton("Go Print");
b.setToolTipText("Print");
b.setMnemonic('p');
gc.insets=new Insets(0,0,200,-450);
getContentPane().add(b,gc);
b.setEnabled(false);

b5=new JButton("Exit");
b5.setToolTipText("Exit");
b5.setMnemonic('x');
gc.insets=new Insets(0,0,200,-600);
getContentPane().add(b5,gc);


h1=new Label("JPRN ");
h1.setFont(new Font("COURIER", Font.BOLD+Font.ITALIC,40));
h1.setForeground(Color.blue);
h1.setBackground(Color.pink);
gc.insets=new Insets(0,0,0,0);
getContentPane().add(h1,gc); 

h2=new Label("A Java Text File Printing Software ");
h2.setFont(new Font("COURIER", Font.BOLD+Font.ITALIC,20));
h2.setForeground(Color.blue);
h2.setBackground(Color.pink);
gc.insets=new Insets(0,0,-100,0);
getContentPane().add(h2,gc); 

i1=new ImageIcon("balu.jpg");
b3=new JButton(i1);
b3.setBackground(Color.pink);
gc.insets=new Insets(0,0,-400,200);
getContentPane().add(b3,gc); 

l3=new JLabel("Developed By  S.Balasubramanian");
gc.insets=new Insets(0,0,-400,-300);
getContentPane().add(l3,gc);

l4=new JLabel("Mail to : spbalu_2k@yahoo.com");
gc.insets=new Insets(0,0,-450,-300);
getContentPane().add(l4,gc);

l5=new JLabel("Copyright : www24.brinkster.com/javajourney");
gc.insets=new Insets(0,0,-500,-300);
getContentPane().add(l5,gc);

b.addActionListener(new LOGIN());
b1.addActionListener(new BROWSE());
b5.addActionListener(new EXIT());
start();
}


public void run()
{

int i=0;
try{
 System.out.println("JPRN--Done by S.Balasubramanian.");
while(true)
{
 Thread.sleep(500);
 if(i==1)
   {
   h1.setForeground(Color.red);
   h2.setForeground(Color.red);
   }
 if(i==2)
   {
   h1.setForeground(Color.blue);
   h2.setForeground(Color.blue);
   //bot1.setForeground(Color.blue);
	}
 if(i==3)
   {
   h1.setForeground(Color.green);
   h2.setForeground(Color.green);
   }
 if(i==4) 
   {
   h1.setForeground(Color.black);
   h2.setForeground(Color.black);
   //bot1.setForeground(Color.black);
   }
 if(i==5)
   {
   h1.setForeground(Color.yellow);
   h2.setForeground(Color.yellow);
   } 


 if(i==6)
   {
   h1.setForeground(Color.orange);
   h2.setForeground(Color.orange);
   }


 if(i==7)
   {
   h1.setForeground(Color.gray);
   h2.setForeground(Color.gray);
   } 

if(i==8)
   {
   h1.setForeground(Color.white);
   h2.setForeground(Color.white);
   } 


 
 i=i+1;
 if(i==9)
   i=0;
}
}catch(Exception e) {System.err.println(e.toString());}

}

public void start()
{
 th1=new Thread(this);
 th1.start();
 System.out.println("Welcome to JPRN!!!");
}

public void stop()
{
 th1.stop();
}



     class LOGIN implements ActionListener
     {
     public void actionPerformed(ActionEvent e)
     {
	//this.setVisible(false);
	String filename=t1.getText();
	new BaluDocPrn(filename);          
	
      }
      }

class BROWSE implements ActionListener
     {
     public void actionPerformed(ActionEvent e)
     {
	Frame f=new Frame("JPrn");
	b.setEnabled(true);
	FileDialog t=new FileDialog(f,"JPrn - Developed By S.Balu");
	t.show();    
	String filen=t.getFile().toString();
	String filed=t.getDirectory();
	t1.setText(filed+filen);
	
      }
      }

class EXIT  implements ActionListener
     {
     public void actionPerformed(ActionEvent e)
     {
	if((JOptionPane.showConfirmDialog(new Frame(),"Are You Sure to close the Session?"))==JOptionPane.YES_OPTION)              
              System.exit(0);
	
      }
      }

public static void main(String a[])
{
jPrn t= new jPrn();
t.resize(800,600);
t.show();


}
}

Downloads

Download source file = 29KB

Dedication: To my brothers and sisters, my parents, my well-wisher Subashini, and SPB.

This code was contributed by S. Balasubramanian.

[To contribute a code article to Gamelan, please contact kmurphy@internet.com.]






Comment and Contribute

 


(Maximum characters: 1200). You have characters left.

 

 


Enterprise Development Update

Don't miss an article. Subscribe to our newsletter below.

By submitting your information, you agree that developer.com may send you developer offers via email, phone and text message, as well as email offers about other products and services that developer believes may be of interest to you. developer will process your information in accordance with the Quinstreet Privacy Policy.

Sitemap

Thanks for your registration, follow us on our social networks to keep up-to-date