Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!


Please modify simple code to print

javakiddojavakiddo Member Posts: 31
hello please modify this code by rewriting the function "printThisFrame()" to simply print the gui frame and its contents. Thank you.

import java.awt.*;
import java.awt.event.*;
import java.applet.Applet;

public class PrtFrame extends Applet {
Label label_1;
TextField textfield_1;
Choice choice_1;
List list_1;
Button printFrameButton;
Button Exit;

* Please modify this function to print
* the gui frame and its contents as they
* appear. Thank you.
public void printThisFrame(){
//please edit this function to print the frame and its contents

public void init() {
PrtFrameLayout customLayout = new PrtFrameLayout();

setFont(new Font("Helvetica", Font.PLAIN, 14));

label_1 = new Label(" I hope you can help");

textfield_1 = new TextField("please modify the code to print this frame");

choice_1 = new Choice();
choice_1.addItem("item 1");
choice_1.addItem("item 2");

list_1 = new List();
list_1.add("item 1");
list_1.add("item 2");

printFrameButton = new Button("printFrameButton");
printFrameButton.addActionListener(new ActionListener() {
public void actionPerformed( ActionEvent e) {
printThisFrame(); }} );

Exit = new Button("Exit");
Exit.addActionListener(new ActionListener() {
public void actionPerformed( ActionEvent e) {
System.exit(0); }} );


public static void main(String args[]) {
PrtFrame applet = new PrtFrame();
Frame window = new Frame("PrtFrame");

window.addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent e) {

window.add("Center", applet);

class PrtFrameLayout implements LayoutManager {

public PrtFrameLayout() {

public void addLayoutComponent(String name, Component comp) {

public void removeLayoutComponent(Component comp) {

public Dimension preferredLayoutSize(Container parent) {
Dimension dim = new Dimension(0, 0);

Insets insets = parent.getInsets();
dim.width = 317 + insets.left + insets.right;
dim.height = 214 + + insets.bottom;

return dim;

public Dimension minimumLayoutSize(Container parent) {
Dimension dim = new Dimension(0, 0);
return dim;

public void layoutContainer(Container parent) {
Insets insets = parent.getInsets();

Component c;
c = parent.getComponent(0);
if (c.isVisible()) {c.setBounds(insets.left+8,,293,32);}
c = parent.getComponent(1);
if (c.isVisible()) {c.setBounds(insets.left+8,,293,32);}
c = parent.getComponent(2);
if (c.isVisible()) {c.setBounds(insets.left+8,,293,32);}
c = parent.getComponent(3);
if (c.isVisible()) {c.setBounds(insets.left+8,,150,63);}
c = parent.getComponent(4);
if (c.isVisible()) {c.setBounds(insets.left+166,,135,24);}
c = parent.getComponent(5);
if (c.isVisible()) {c.setBounds(insets.left+166,,135,24);}
Ghassan A.


  • chamsterchamster Member Posts: 662
    : hello please modify this code by rewriting the function "printThisFrame()" to simply print the gui frame and its contents. Thank you.

    You could use Robot-class and capture the screen but i'm not sure if the frame will be caught or left out. Anyway, give it a try and (most likely) you'll get an image to print.

    Kind Regards
    (+46/0) 708-70 73 92
    [email protected]

  • Andre YoungAndre Young USAMember Posts: 0

    _____ | | free video tutorials and ebooks about [ Visual Basic, C, Delphi, C#, Objective-C, Scratch, C++, Visual Basic .NET, Assembly, Java, R, Go, Python, Ruby, Perl, PL/SQL, MATLAB, JavaScript, PHP, Swift Rust, Scheme, FoxPro, Awk, Lisp, Alice, Fortran, Transact-SQL, ABAP, Dart, Clojure, Prolog, COBOL, Scala, LabVIEW, Logo, D, Julia, Hack, F#, ML, Lua, Bash, Erlang, SAS, Ada, VBScript, Apex, Crystal, Kotlin ] ___________

Sign In or Register to comment.