* */ public JavaWorldPrintExample1() { //--- Create a printerJob object PrinterJob printJob = PrinterJob.getPrinterJob(); //--- Set the printable class to this one since we //--- are implementing the Printable interface printJob.setPrintable(this); //--- Show a print dialog to the user. If the user //--- click the print button, then print otherwise //--- cancel the print job if (printJob.printDialog()) { try { printJob.print(); } catch (Exception PrintException) { PrintException.printStackTrace(); } } } /** * Method: print *
* * This class is responsible for rendering a page using the provided * parameters. The result will be a grid where each cell will be half an * inch by half an inch. * * @param g * a value of type Graphics * @param pageFormat * a value of type PageFormat * @param page * a value of type int * @return a value of type int */ public int print(Graphics g, PageFormat pageFormat, int page) { int i; Graphics2D g2d; Line2D.Double line = new Line2D.Double(); //--- Validate the page number, we only print the first page if (page == 0) { //--- Create a graphic2D object a set the default parameters g2d = (Graphics2D) g; g2d.setColor(Color.black); //--- Translate the origin to be (0,0) g2d.translate(pageFormat.getImageableX(), pageFormat .getImageableY()); //--- Print the vertical lines for (i = 0; i < pageFormat.getWidth(); i += INCH / 2) { line.setLine(i, 0, i, pageFormat.getHeight()); g2d.draw(line); } //--- Print the horizontal lines for (i = 0; i < pageFormat.getHeight(); i += INCH / 2) { line.setLine(0, i, pageFormat.getWidth(), i); g2d.draw(line); } return (PAGE_EXISTS); } else return (NO_SUCH_PAGE); } } //Example1 import java.awt.print.PrinterJob; public class Test$36{ public static void main(String args[]){ System.out.println("hello world"); PrinterJob pj= PrinterJob.getPrinterJob(); pj.printDialog(); } } ------------------------------------------------------------------------------------------------- import java.io.BufferedReader; import java.awt.Graphics; import java.awt.print.PageFormat; import java.awt.print.Printable; import java.awt.print.PrinterException; import java.awt.print.PrinterJob; import java.io.*; import javax.swing.JPanel; public class Test$37 extends JPanel { public static void main(String[] args)throws Exception { try { PrinterJob pjob = PrinterJob.getPrinterJob(); // pjob.setJobName("Graphics Demo Printout"); pjob.setCopies(1); pjob.setPrintable(new Printable() { public int print(Graphics pg, PageFormat pf, int pageNum) { if (pageNum > 0) // we only print one page return Printable.NO_SUCH_PAGE; // ie., end of job try{ FileReader fr = new FileReader("Test$37.java"); BufferedReader br = new BufferedReader(fr); String temp=" "; int i=30; while((temp=br.readLine())!=null){ i=i+15; pg.drawString(temp, 50, i); } }catch(Exception e){} return Printable.PAGE_EXISTS; } }); if (pjob.printDialog() == false) // choose printer return; pjob.print(); } catch (Exception pe) { pe.printStackTrace(); } } }import java.awt.EventQueue; import javax.swing.JFrame; import javax.swing.JWindow; import javax.swing.JLabel; import java.awt.BorderLayout; import javax.swing.SwingConstants; import javax.swing.JDesktopPane; import javax.swing.BorderFactory; import javax.swing.*; import java.awt.*; public class test$38 extends JFrame implements Runnable{ test$38(){ JDesktopPane tp = new JDesktopPane(); tp.setBorder(BorderFactory.createEmptyBorder()); //tp.setDragMode(JDesktopPane.OUTLINE_DRAG_MODE); //JFrame f = new JFrame(); JLabel welcome = new JLabel("Welcome: Today is " + new java.util.Date() + " ", JLabel.CENTER); getContentPane().add(welcome, BorderLayout.PAGE_END, JLabel.CENTER); getContentPane().add(tp); /* welcome.setFont(new Font("monospaced", Font.PLAIN, 12)); welcome.setForeground(Color.blue); JDesktopPane desktop = new JDesktopPane(); desktop.setBorder(BorderFactory.createEmptyBorder()); desktop.setDragMode(JDesktopPane.OUTLINE_DRAG_MODE); //getContentPane().add(welcome, BorderLayout.PAGE_END, JLabel.CENTER); getContentPane().add(desktop, BorderLayout.CENTER); */ setVisible(true); setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); //JLabel t= new JLabel("balaji",SwingConstants.CENTER); //JWindow w= new JWindow(); //w.add(t); //,BorderLayout.CENTER); //w.setBounds(200,300,300,300); //w.setVisible(true); } public void run(){ System.out.println("event queue demo run "); } public static void main(String args[]){ System.out.println("event queue demo"); EventQueue.invokeLater(new test$38()); } } ------------------------------------------------------------------------------------------------- import java.awt.*; import java.awt.event.*; import javax.swing.*; import javax.swing.event.*; class addremove extends JPanel implements ActionListener{ private JButton addbut; private JButton revbut; private JPanel panel1; private JPanel panel2; public addremove() { addbut = new JButton ("Add"); revbut = new JButton ("Remove"); panel1 = new JPanel(); panel2 = new JPanel(); panel1.setBackground(Color.blue); panel2.setBackground(Color.red); setPreferredSize (new Dimension (218, 160)); setLayout (null); add (addbut); add (revbut); add (panel2); addbut.setBounds (20, 120, 80, 25); revbut.setBounds (120, 120, 80, 25); panel1.setBounds (20,10,180,60); panel2.setBounds (20,10,180,60); } public void actionPerformed(ActionEvent e) { if(e.getSource() == addbut) { remove(panel2); add(panel1); } else if (e.getSource() == revbut) { remove(panel1); add(panel2); } } public static void main (String[] args) { JFrame frame = new JFrame ("addremove"); frame.setDefaultCloseOperation (JFrame.EXIT_ON_CLOSE); frame.getContentPane().add (new addremove()); frame.pack(); frame.setVisible (true); frame.setLocation(450,280); frame.setResizable(false); } } interface xyz{ void print(); void print1(); } class one implements xyz{ public void print(){ System.out.println("class one"); } public void print1(){ System.out.println("class one"); } } class two implements xyz{ public void print(){ System.out.println("class two"); } public void print1(){ System.out.println("class one"); } } public class test$4 { public static void main(String args[]){ System.out.println("hello world"); one o= new one(); two t= new two(); t.print(); o.print(); } } public class test$40{ public static void main(String arfs[]){ new test$41(); } } public class test$41{ public test$41(){ System.out.println("hello world"); } } import java.util.Map; import java.util.Properties; import java.io.Console; import java.io.PrintWriter; public class test$42{ public static void main(String args[])throws Exception{ System.out.println("Shut down program"); Properties p = new Properties(); Runtime r= Runtime.getRuntime(); //r.exec("shutdown -l"); String temp; p=System.getProperties(); //System.out.println(temp); //System.out.println(System.getProperty("user.home")); //System.out.println(System.getProperties()); //System.out.println(System.getProperty("sun.boot.library.path")); //System.out.println(p.toString()); //System.out.println(System.getenv()); //Console.WriteLine("hello"); Console c= System.console(); String temp1=c.readLine(); char[] c1= c.readPassword("enter password: "); System.out.println(c1); System.out.println(temp1); c.printf("esdfsd"+"hello","balaji"); PrintWriter out= c.writer(); out.println("hello world"); } } ------------------------------------------------------------------------------------------------- /* (#)System program (#)10 aug 2011 (#)author : bala */ import java.awt.event.WindowAdapter; import java.awt.event.WindowEvent; import java.util.StringTokenizer; import java.util.Properties; import javax.swing.JFrame; import java.awt.event.ActionListener; import java.awt.event.ActionEvent; import javax.swing.JButton; import javax.swing.JPanel; import java.awt.FlowLayout; import java.awt.Container; import javax.swing.JOptionPane; import java.lang.Runtime; import javax.swing.JLabel; import javax.swing.JTextArea; import javax.swing.JScrollPane; public class test$43 extends JFrame implements ActionListener { private JButton sdown; private JButton loff; private JButton rstrt; private JButton suser; private JButton env; private JButton prp; private JButton abt; private JPanel p; private Container ct; private Runtime r; private Properties pr; private StringTokenizer st; private JTextArea ta; public test$43(){ //super("System program"); sdown= new JButton("Shut Down"); loff=new JButton("Log Off"); rstrt=new JButton("Restart"); suser=new JButton("Switch User"); env=new JButton("Environment Variables"); prp=new JButton("System Properties"); abt= new JButton("About"); p= new JPanel(); //p.setLayout(new FlowLayout()); r= Runtime.getRuntime(); ct= getContentPane(); ct.setLayout(new FlowLayout()); ct.add(sdown); ct.add(loff); ct.add(rstrt); ct.add(suser); ct.add(env); ct.add(prp); ct.add(abt); sdown.addActionListener(new ActionListener(){ public void actionPerformed(ActionEvent e){ System.out.println(e.getActionCommand()); try{ r.exec("shutdown -s"); } catch(Exception e1){ } } } ); loff.addActionListener(new ActionListener(){ public void actionPerformed(ActionEvent e){ System.out.println(e.getActionCommand()); try{ r.exec("shutdown -l"); } catch(Exception e1){} } } ); rstrt.addActionListener(new ActionListener(){ public void actionPerformed(ActionEvent e){ System.out.println(e.getActionCommand()); try{ r.exec("shutdown -r"); } catch(Exception e1){} } } ); suser.addActionListener(new ActionListener(){ public void actionPerformed(ActionEvent e){ System.out.println(e.getActionCommand()); try{ r.exec("shutdown -l"); } catch(Exception e1){} } } ); env.addActionListener(new ActionListener(){ public void actionPerformed(ActionEvent e){ System.out.println(e.getActionCommand()); //JOptionPane.showMessageDialog(null,"\n"+System.getenv()); String temp; temp=JOptionPane.showInputDialog("Enter environment variable Name??"); System.out.println(temp); if(temp.equals("")){ JOptionPane.showMessageDialog(null,"\nfield not be empty"); } else{ JOptionPane.showMessageDialog(null,"\n"+System.getenv(temp)); } } } ); prp.addActionListener(new ActionListener(){ public void actionPerformed(ActionEvent e){ System.out.println(e.getActionCommand()); pr= new Properties(); pr=System.getProperties(); String temp=pr.toString(); String temp1=""; System.out.println(temp); st= new StringTokenizer(temp,","); int i=0; while(st.hasMoreTokens()){ i++; temp1=temp1+"\n"+st.nextToken(); } JFrame jf= new JFrame(); ta= new JTextArea(); ta.setText(temp1); jf.setVisible(true); jf.setSize(1024,768); jf.setDefaultCloseOperation(EXIT_ON_CLOSE); jf.add(ta); System.out.println(temp1); //new Text(temp1); } } ); abt.addActionListener(new ActionListener(){ public void actionPerformed(ActionEvent e){ System.out.println(e.getActionCommand()); JOptionPane.showMessageDialog(null,"\nSystem Program\nVersion 1.0\nCopy Right@ 2011 SSK Technologies\n"); } } ); setResizable(false); setSize(400,100); setVisible(true); setDefaultCloseOperation(EXIT_ON_CLOSE); setTitle("System program"); } public void actionPerformed(ActionEvent e){ } public static void main(String args[])throws Exception{ System.out.println("shutdown gui"); new test$43(); } } ------------------------------------------------------------------------------------------------- import java.io.*; import java.util.Properties; class App { public static void main( String[] args ) { Properties prop = new Properties(); try { //set the properties value prop.setProperty("database", "localhost"); prop.setProperty("dbuser", "mkyong"); prop.setProperty("dbpassword", "password"); //save properties to project root folder prop.store(new FileOutputStream("config.properties"), null); } catch (IOException ex) { ex.printStackTrace(); } } }import java.lang.String; public class test$5{ test$5(String s){ } public String toString(String s){ return s; } public static void main(String args[]){ System.out.println("hello world"); String s="hello "; String ss= "balaji"; System.out.println(s+ss); System.out.println(s.equals(ss)); char sss; sss=s.charAt(0); System.out.println(sss); sss=ss.charAt(0); System.out.println(sss); //string str= s.subString(1,3); test$5 t= new test$5("test$5 program"); System.out.println(t); } }class ExA extends Exception{ ExA(String s ){ super(s); } } class ExB extends Exception{ ExB(String s){ super(s); } } ------------------------------------------------------------------------------------------------- public class test$6{ public static void main(String args[]) { System.out.println("hello world"); try{ print(); } catch(ExB e){ System.out.println(e); e.printStackTrace(); } } public static void print()throws ExB{ System.out.println("print method"); throw new ExB("just testing.."); } } ------------------------------------------------------------------------------------------------- public class Test$7{ public static void main(String args[]){ System.out.println("test 7 program"); float f; f=100.25034500f; double d; d=4646.1634; System.out.println(f); System.out.println(d); } }interface base3{ } interface base4{ } class base{ } class base1{ } class derived1 extends base implements base3,base4 { } class derived2 extends base{ } public class Test$8 { public static void main(String args[]){ System.out.println("test program"); } }public class test$9 { public static void main(String args[]){ System.out.println("test9 program"); String s=new String("one"); s=new String("two"); System.out.println(s); StringBuffer s1=new StringBuffer("hello"); System.out.println(s1); } } ------------------------------------------------------------------------------------------------- import java.awt.event.WindowAdapter; import java.awt.event.WindowEvent; import java.util.StringTokenizer; import java.util.Properties; import javax.swing.JFrame; import java.awt.event.ActionListener; import java.awt.event.ActionEvent; import javax.swing.JButton; import javax.swing.JPanel; import java.awt.FlowLayout; import java.awt.Container; import javax.swing.JOptionPane; import java.lang.Runtime; import javax.swing.JLabel; import javax.swing.JTextArea; import javax.swing.JScrollPane; import java.awt.FlowLayout; import java.awt.Container; public class Text extends JFrame{ public Text(String temp1){ Container ct= getContentPane(); ct.setLayout(new FlowLayout()); JTextArea ta= new JTextArea(); JScrollPane jsp=new JScrollPane(ta); ct.add(jsp); ta.setText(temp1); ct.add(ta); setTitle("System properties"); setSize(1024,768); setVisible(true); setDefaultCloseOperation(EXIT_ON_CLOSE); addWindowListener(new WindowAdapter(){ public void windowClosing(WindowEvent e){ //dispose(); } } ); } /* public static void main(String args[]){ new Text("dsfsdf"); } */ }
No comments:
Post a Comment