Swing and AWT Problem


Swing and AWT Problem

Swing and AWT Problem
0 Answer(s)      8 years ago
Posted in : Swing AWT
hi sir i have a problem i know from one Jframe we can send values to another Jframe.

so in my project i have one fame containing three textfields
String a=TNa.getText().toString();
String b=TCo.getText().toString();
String c=TCl.getText().toString();

applicationclient1.DrawingCanvas obj=new applicationclient1.DrawingCanvas();

applicationclient1.AnotherPrintDemo mn=new applicationclient1.AnotherPrintDemo();

and another Frame is

public class AnotherPrintDemo extends JFrame {
DrawingCanvas canvas;

JButton setUpButton = new JButton("Page Setup");

JButton printButton = new JButton("Print");

JButton cancelButton = new JButton("Cancel");

public AnotherPrintDemo() {
Container container = getContentPane();

canvas = new DrawingCanvas();

JPanel panel = new JPanel(new GridLayout(1, 3));

ButtonListener buttonListener = new ButtonListener();



container.add(BorderLayout.SOUTH, panel);

addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent e) {
setSize(520, 500);

class ButtonListener implements ActionListener {
PrinterJob printJob;

PageFormat pageFormat;

PrintableCanvas printableCanvas;

ButtonListener() {
printJob = PrinterJob.getPrinterJob();
pageFormat = printJob.defaultPage();

public void actionPerformed(ActionEvent e) {
JButton tempButton = (JButton) e.getSource();

if (tempButton.equals(setUpButton)) {
pageFormat = printJob.pageDialog(pageFormat);
} else if (tempButton.equals(printButton)) {
printableCanvas = new PrintableCanvas(pageFormat);

boolean ok = printJob.printDialog();
if (ok) {
try {
} catch (Exception pe) {
System.out.println("Printing Exception Occured!");
} else if (tempButton.equals(cancelButton)) {
applicationclient1.NewJFrame mn=new applicationclient1.NewJFrame();


public static void main(String arg[]) {
new AnotherPrintDemo();

class DrawingCanvas extends JPanel {
Font font;
String Na;
String Co;
String Cl;
FontMetrics fontMetrics;

int w, h;

DrawingCanvas() {
setSize(500, 470);

w = this.getWidth();
h = this.getHeight();

font = new Font("Dialog", Font.BOLD, 12);
fontMetrics = getFontMetrics(font);

public void paintComponent(Graphics g) {
Graphics2D g2D = (Graphics2D) g;

paintContent(g2D, w, h);

public void paintContent(Graphics2D g2D, int w, int h) {
g2D.drawRoundRect(70, 70,350,280,10,10);
g2D.drawLine(70,120 ,420,120);
g2D.drawLine(320, 120, 320, 350);
g2D.drawLine(70, 305, 420, 305);
g2D.drawString("NAME :", 75,90);
g2D.drawString(Na,125 ,90);
g2D.drawString("COURSE :",75 ,115 );
g2D.drawString(Co,135, 115);
g2D.drawString("CLASS :",270, 115);
g2D.drawString(Cl,320 ,115);
g2D.drawString("Amount :", 75,160);
g2D.drawString("Balance :", 75,200);
g2D.drawString("Total :", 75,300);
g2D.drawString("Recieved :", 75,330);


class PrintableCanvas implements Printable {
DrawingCanvas canvas;

PageFormat pageFormat;

public PrintableCanvas(PageFormat pf) {
pageFormat = pf;

public int print(Graphics g, PageFormat pageFormat, int pageIndex)
throws PrinterException {
if (pageIndex >= 1) {
return Printable.NO_SUCH_PAGE;

Graphics2D g2D = (Graphics2D) g;

canvas = new DrawingCanvas();

canvas.paintContent(g2D, (int) pageFormat.getImageableWidth(),
(int) pageFormat.getImageableHeight());

// successful printing of the page
return Printable.PAGE_EXISTS;

so i want to send those three textfields values to the next frame into
g2D.drawString(Na,125 ,90);
g2D.drawString(Co,135, 115);
g2D.drawString(Cl,320 ,115);

how can i get those textfields values to these three String variable
please reply cir as much as possible i have to submit my project within four days

View Answers

Related Tutorials/Questions & Answers:
Swing and AWT Problem - Swing AWT
Swing and AWT Problem  hi sir i have a problem i know from one Jframe we can send values to another Jframe. so in my project i have one fame containing three textfields CODE: String a=TNa.getText().toString(); String b
tooltip problem - Swing AWT
tooltip problem  Hi All, I am using SWT_AWT bridge in my code to embed swing components into SWT Composite. I am using a Swing JButton in SWT Composite. My problem is that I am unable to see the tooltip for this button even
problem in swing-awt
problem in swing-awt  I am doing project in core java and i am facing one problem. I have to add command prompt(terminal) to the fream at bottom but not getting the solution. So please help me. thanks and regards, Aakash
problem with JTable - Swing AWT
problem with JTable  hi guys, i was a student and i am very new to swings.i was having an assignment like i need to create a JTable with checkboxes inside it.i do have another checkbox outside the Table.i need to write
Java Problem Steps - Swing AWT
Java Problem Steps  How to create a Jar File From the Dos prompt of a Swing program having two classes in the program with one is public class one of them
Multiple session problem - Swing AWT
Multiple session problem  I am working in a Linux based java swing application. Problem: I have optimized JDialog and JPanel for my use.... This problem is quite critical as UI looks quite unpredictable due
Jfree chart problem - Swing AWT
Jfree chart problem  hello i have a problem related to jfree chart i have some data and i want to display data in two different chart stacked area chart and line chart both in a single frame. That is hybrid combination
Java Swings problem - Swing AWT
Java Swings problem  Sir, I am facing a problem in JSplitPane. I want the divider in the splitpane to be customized. I have a splitpane with Horizontal orientation and here, there lies the divider between left component and right
Frame refresh problem - Swing AWT
to correct this problem....its urgent!! thnks in adv..  Hi Friend
SWT_AWT bridge ,jtextfield edit problem - Swing AWT
_AWT bridge frame and adding JTextfield to it, My problem is that the JTextfield...(display); shell.setText("Using Swing and AWT"); shell.setSize(350...SWT_AWT bridge ,jtextfield edit problem  Hi All, I am using SWT_AWT
AWT & SWING  What is diffennce between AWT & SWING
New Problem in Form Resizing - Swing AWT
New Problem in Form Resizing  Hi, I am using a MDI application...)); The problem is arising when the user resizes the form. The EditorPane(old... HeadPane.setBounds(0, 0, this.getWidth(), 100); But it creates another problem. it overwrites
Problem when resizing the form - Swing AWT
Problem when resizing the form  Hi, I am facing a problem when resizing the form. I have a JTextPane on the JInternalFrame which occupy all... The EditorPane(Old) overlaps the HeadPane(new). I think this problem is occuring whenever
swing-awt - Swing AWT
swing-awt  Hi, Thanks for replying to my question...I'm getting some confusion to add action events in my application(Rich Text Editor).How to add action events? Thank U
swing/awt - Swing AWT
swing/awt  How to create richtexteditor using swings...?I'm very much new to swings....It's urgent.....Thank u...   hello read this book you get idea; JFC Swing Tutorial, The: A Guide to Constructing GUIs, Second
java - Swing AWT
What is Java Swing AWT  What is Java Swing AWT
Basic Diffence between Swing-AWT - Swing AWT
Basic Diffence between Swing-AWT  What is Basic Diffence between Swing-AWT
awt - Swing AWT
market chart this code made using "AWT" . in this chart one textbox when user..., For solving the problem visit to : http://www.roseindia.net/java/example/java/awt/ Thanks
AWT programmes - Swing AWT
AWT programmes  I need few programs for menus in AWT. how to open a filed dialog window, and how to save a image in the save window when we press... has all AWT programms which must open,save and make changes to a particular
query - Swing AWT
java swing awt thread query  Hi, I am just looking for a simple example of Java Swing
awt swings - Swing AWT
awt swings  hello sir, My requirement is to insert captured image from cam onto a frame and from that place i hve to save it in the database(MySql).its urgent sir.it is a part of my project..if code is available
java swing - Swing AWT
java swing  how i can insert multiple cive me exampleolumn and row in one JList in swing?plz g  Hi Friend, Please clarify your question. Thanks
Swing paint - Swing AWT
Swing paint  hi, i want to print something on window using swing applet.. m doing dis.. protected void paintComponent(Graphics g... the Swing Applet, use html file with the following code: Java Applet Demo
java swing - Swing AWT
java swing   how i can insert in JFrame in swing?  Hi Friend, Try the following code: import java.awt.*; import javax.swing.*; import java.awt.event.*; class FormDemo extends JFrame { JButton ADD; JPanel
java swing - Swing AWT
java swing  how to add image in JPanel in Swing?  Hi Friend, Try the following code: import java.awt.*; import java.awt.image....: http://www.roseindia.net/java/example/java/swing/ Thanks
SWING  how can i insert image in Jpanel by extending class with JFrame in swing?  Hi Friend, Try the following code: import java.awt.*; import java.awt.image.*; import java.io.*; import javax.imageio.*; import
java swing - Swing AWT
java swing   Iam developing a java web browser.Actually my code works fine ie. i can load a web page without proxy.But in my place i have only proxy servers through which i should visit any web site.So, i want my browser also
swing - Swing AWT
swing   how to create JTabbedPane.when i choose one jtabbedpane it will appear JTextField,resultMessages.pls give me any examples  Hi Friend, Try the following code: import javax.swing.*; import java.awt.
SWING  how to insert image and components such as JLabel,JButton,JTextfield in JFrame in swing?  Hi Friend, Try the following code: import java.io.*; import java.awt.*; import javax.swing.*; import
Swing question - Swing AWT
Swing question  I want to move a string in JFrame similarily as done by marquee tag in HTML.The string should move from right to left. How can I do this?  Hi Friend, Try the following code: import java.awt.
swing with jdbc - Swing AWT
swing with jdbc  Hi, i m developing the desktop application using swing.i want to use table structure for that.also its DB specific application. i have some problems with swing using jdbc. 1. the values entered in table