Пример #1
0
  public PrintTestFrame() {
    canvas = new PrintComponent();
    add(canvas, BorderLayout.CENTER);

    attributes = new HashPrintRequestAttributeSet();

    JPanel buttonPanel = new JPanel();
    JButton printButton = new JButton("Print");
    buttonPanel.add(printButton);
    printButton.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent event) {
            try {
              PrinterJob job = PrinterJob.getPrinterJob();
              job.setPrintable(canvas);
              if (job.printDialog(attributes)) job.print(attributes);
            } catch (PrinterException e) {
              JOptionPane.showMessageDialog(PrintTestFrame.this, e);
            }
          }
        });

    JButton pageSetupButton = new JButton("Page setup");
    buttonPanel.add(pageSetupButton);
    pageSetupButton.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent event) {
            PrinterJob job = PrinterJob.getPrinterJob();
            job.pageDialog(attributes);
          }
        });

    add(buttonPanel, BorderLayout.NORTH);
    pack();
  }
Пример #2
0
  public PrintDemoGfx(boolean q) {
    quiet = q;
    final JFrame f = new JFrame("Printing Test Dummy Frame");

    // Construct the object we want to print. Contrived:
    // this object would already exist in a real program.
    final GfxDemoCanvas thing = new GfxDemoCanvas(400, 300);

    f.getContentPane().add(thing, BorderLayout.CENTER);

    JButton printButton = new JButton("Print");
    f.getContentPane().add(printButton, BorderLayout.SOUTH);

    printButton.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent e) {
            try {
              PrinterJob pjob = PrinterJob.getPrinterJob();
              pjob.setJobName("DemoGfx - Graphics Demo Printout");
              pjob.setCopies(1);
              // Tell the print system how to print our pages.
              pjob.setPrintable(
                  new Printable() {
                    /** called from the printer system to print each page */
                    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

                      // Now (drum roll please), ask "thing" to paint itself
                      // on the printer, by calling its paint() method with
                      // a Printjob Graphics instead of a Window Graphics.
                      thing.paint(pg);

                      // Tell print system that the page is ready to print
                      return Printable.PAGE_EXISTS;
                    }
                  });

              if (!quiet && pjob.printDialog() == false) // choose printer
              return; // user cancelled

              pjob.print(); // Finally, do the printing.
            } catch (PrinterException pe) {
              JOptionPane.showMessageDialog(
                  f, "Printer error" + pe, "Printing error", JOptionPane.ERROR_MESSAGE);
            }
          }
        });

    f.pack();
    f.setVisible(true);
  }
Пример #3
0
  public reminder(int m, int y, int m3, int y3) {
    m1 = m;
    y1 = y;
    m2 = m3;
    y2 = y3;

    try {
      f.setIconImage(Toolkit.getDefaultToolkit().getImage(getClass().getResource("skrm.jpg")));
      String cn = UIManager.getSystemLookAndFeelClassName();

      UIManager.setLookAndFeel(cn); // Use the native L&F
    } catch (Exception cnf) {
      System.out.println(cnf);
    }

    f = new JFrame("Print Reminders");
    f.setVisible(true);
    f.setLayout(null);
    f.setSize(300, 100);
    f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    f.addWindowListener(
        new WindowAdapter() {
          public void windowClosing(WindowEvent e) {
            System.exit(0);
          }
        });
    b = new JButton("Print Reminders");
    b.addActionListener(this);
    back = new JButton("Back");
    back.addActionListener(this);
    f.add(b);
    b.setBounds(10, 10, 100, 20);
    b.setMnemonic('P');
    f.add(back);
    back.setMnemonic('B');
    back.setBounds(150, 10, 100, 20);
    // f.pack();

  }