Results 1 to 4 of 4
  1. #1
    mitra is offline Member
    Join Date
    Jun 2011
    Posts
    59
    Rep Power
    0

    Default JApplet drawing printing

    Hi everybody.........

    I have a problem with my program. And I need ur help.........

    Java Code:
    package freeHandDrawJappletInternalFrame;
    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;
    
    public class PrintApplet2 extends JApplet implements ActionListener {
        Graphics2D g2;
        CanvasPrint2 fdc;
        
        @Override
      public void init(){
          this.setLayout(new BorderLayout());
          JPanel panel = new JPanel();
          this.add(panel);
          Button print = new Button("Print");
          print.addActionListener(this);
          fdc = new CanvasPrint2();
          panel.add(fdc,BorderLayout.NORTH);
          panel.add(print,BorderLayout.SOUTH);
    
          
      }
    
        @Override
        public void actionPerformed(ActionEvent e) {
        }
    }
    
    class CanvasPrint2 extends Canvas {
        public CanvasPrint2() {
            setSize(200, 200);
            setBackground(Color.yellow);
        }
        
        @Override
        public void paint(Graphics g) {
                //CanvasPrint1(){
        Graphics2D g2 = (Graphics2D) g;
            //Graphics2D g2 = null;
        g2.setColor(Color.blue);
        g2.drawLine(30, 30, 80, 80);
        g2.drawRect(20, 150, 100, 100);
        g2.fillRect(20, 150, 100, 200); 
        g2.fillOval(150, 20, 100, 100); 
        }
    }
    now I want to print the drawing objects over the CanvasPrint2 class through my printer.
    Not the whole applet, just the area specified by the CanvasPrint2 () constructor.

    And how can I do it?
    Please help......

    Thanks
    Last edited by mitra; 10-12-2011 at 02:31 PM.

  2. #2
    KevinWorkman's Avatar
    KevinWorkman is offline Crazy Cat Lady
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    4,038
    Rep Power
    10

    Default Re: JApplet drawing printing

    Can't you just draw it to a BufferedImage, and then print that out?
    How to Ask Questions the Smart Way
    Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!

  3. #3
    mitra is offline Member
    Join Date
    Jun 2011
    Posts
    59
    Rep Power
    0

    Default Re: JApplet drawing printing

    Quote Originally Posted by KevinWorkman View Post
    Can't you just draw it to a BufferedImage, and then print that out?
    Thank you very much for your reply.........
    can you provide me a sample base on the above program?

  4. #4
    mitra is offline Member
    Join Date
    Jun 2011
    Posts
    59
    Rep Power
    0

    Default Re: JApplet drawing printing

    Kevin as you said, I have tried bufferedImage() method.
    First I have created and save image in a location and then from it I have printed out. But the image and printout both are too poor in quality, its not so clear, hazy.

Similar Threads

  1. Replies: 9
    Last Post: 08-19-2011, 01:59 AM
  2. JApplet only drawing 1/5 of my app and then greying out
    By CrashWave in forum Java Applets
    Replies: 2
    Last Post: 04-09-2011, 10:12 PM
  3. printing string backwards and printing every other
    By droidus in forum New To Java
    Replies: 22
    Last Post: 03-10-2011, 10:17 AM
  4. JApplet on MAC
    By ld_pvl in forum Java Applets
    Replies: 0
    Last Post: 08-23-2009, 02:40 PM
  5. JFrame to JApplet or JApplet to JApplet
    By ramesh.8189 in forum AWT / Swing
    Replies: 13
    Last Post: 02-08-2009, 07:14 AM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •