Howdy, Stranger!

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

Categories

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));
setLayout(customLayout);

label_1 = new Label(" I hope you can help");
label_1.setBackground(Color.orange);
add(label_1);

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

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

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

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

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

setSize(getPreferredSize());
}

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

window.addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent e) {
System.exit(0);
}
});

applet.init();
window.add("Center", applet);
window.pack();
window.setVisible(true);
}
}

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.top + 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,insets.top+8,293,32);}
c = parent.getComponent(1);
if (c.isVisible()) {c.setBounds(insets.left+8,insets.top+48,293,32);}
c = parent.getComponent(2);
if (c.isVisible()) {c.setBounds(insets.left+8,insets.top+87,293,32);}
c = parent.getComponent(3);
if (c.isVisible()) {c.setBounds(insets.left+8,insets.top+127,150,63);}
c = parent.getComponent(4);
if (c.isVisible()) {c.setBounds(insets.left+166,insets.top+127,135,24);}
c = parent.getComponent(5);
if (c.isVisible()) {c.setBounds(insets.left+166,insets.top+158,135,24);}
}
}
Ghassan A.
checkout==> http://groups.yahoo.com/group/thesaudiFriends

Comments

  • 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
    Konrad
    ----------------------------
    (+46/0) 708-70 73 92
    chamster@home.se
    http://konrads.webbsida.com

  • Andre YoungAndre Young USAMember Posts: 0

    _____ | http://forcoder.org | 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.