You are not logged in.

  • Login

1

Saturday, June 5th 2010, 7:11pm

Wie kann man in Java ein gesamtes JFrame ausdrucken?

Hallo,

ich möchte ein JFrame erstellen, welches nur Text beinhaltet, und dieses an einen Drucker weiterleiten.
Als Beispielcode, da mein eigentlicher Code ziemlich lang ist:

Java Quellcode

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.event.*;
 
/**
  *
  * Beschreibung
  *
  * @version 1.0 vom 06.06.2010
  * @author
  */
 
public class HelloWorld extends JFrame {
  // Anfang Attribute
  private Label S1 = new Label();
  private Label S2 = new Label();
  private Label S3 = new Label();
  private Label S4 = new Label();
  private Label S5 = new Label();
  // Ende Attribute
 
  public HelloWorld(String title) {
    // Frame-Initialisierung
    super(title);
    setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
    int frameWidth = 300;
    int frameHeight = 300;
    setSize(frameWidth, frameHeight);
    Dimension d = Toolkit.getDefaultToolkit().getScreenSize();
    int x = (d.width - getSize().width) / 2;
    int y = (d.height - getSize().height) / 2;
    setLocation(x, y);
    Container cp = getContentPane();
    cp.setLayout(null);
    // Anfang Komponenten
 
    S1.setBounds(8, 8, 175, 37);
    S1.setText("Hello World!");
    S1.setFont(new Font("MS Sans Serif", Font.PLAIN, 28));
    cp.add(S1);
    S2.setBounds(32, 40, 175, 37);
    S2.setText("Hello World!");
    S2.setFont(new Font("MS Sans Serif", Font.PLAIN, 13));
    cp.add(S2);
    S3.setBounds(56, 72, 175, 37);
    S3.setText("Hello World!");
    S3.setFont(new Font("MS Sans Serif", Font.PLAIN, 13));
    cp.add(S3);
    S4.setBounds(80, 104, 175, 37);
    S4.setText("Hello World!");
    S4.setFont(new Font("MS Sans Serif", Font.PLAIN, 13));
    cp.add(S4);
    S5.setBounds(104, 136, 175, 37);
    S5.setText("Hello World!");
    S5.setFont(new Font("MS Sans Serif", Font.PLAIN, 13));
    cp.add(S5);
    // Ende Komponenten
 
    setResizable(false);
    setVisible(true);
  }
 
  // Anfang Methoden
  // Ende Methoden
 
  public static void main(String[] args) {
    new HelloWorld("HelloWorld");
  }
}

This post has been edited 1 times, last edit by "Haggi94" (Jun 6th 2010, 9:07am)


Social bookmarks