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=TCo.getText().toString();
String c=TCl.getText().toString();
applicationclient1.DrawingCanvas obj=new applicationclient1.DrawingCanvas();
obj.Cl=a;
obj.Co=b;
obj.Na=c;
applicationclient1.AnotherPrintDemo mn=new applicationclient1.AnotherPrintDemo();
mn.setVisible(true);
this.dispose();
this.setVisible(false);
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() {
super();
Container container = getContentPane();
canvas = new DrawingCanvas();
container.add(canvas);
JPanel panel = new JPanel(new GridLayout(1, 3));
ButtonListener buttonListener = new ButtonListener();
setUpButton.addActionListener(buttonListener);
panel.add(setUpButton);
printButton.addActionListener(buttonListener);
panel.add(printButton);
cancelButton.addActionListener(buttonListener);
panel.add(cancelButton);
container.add(BorderLayout.SOUTH, panel);
addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent e) {
System.exit(0);
}
});
setSize(520, 500);
setVisible(true);
}
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);
printJob.validatePage(pageFormat);
} else if (tempButton.equals(printButton)) {
printableCanvas = new PrintableCanvas(pageFormat);
printJob.setPrintable(printableCanvas);
boolean ok = printJob.printDialog();
if (ok) {
try {
printJob.print();
} catch (Exception pe) {
System.out.println("Printing Exception Occured!");
pe.printStackTrace();
}
}
} else if (tempButton.equals(cancelButton)) {
printJob.cancel();
applicationclient1.NewJFrame mn=new applicationclient1.NewJFrame();
mn.setVisible(true);
}
}
}
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() {
setBackground(Color.white);
setSize(500, 470);
w = this.getWidth();
h = this.getHeight();
font = new Font("Dialog", Font.BOLD, 12);
fontMetrics = getFontMetrics(font);
}
public void paintComponent(Graphics g) {
super.paintComponent(g);
Graphics2D g2D = (Graphics2D) g;
paintContent(g2D, w, h);
}
public void paintContent(Graphics2D g2D, int w, int h) {
g2D.setFont(font);
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.setPaint(Color.black);
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 AWTSwing 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 AWTtooltip 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
Advertisements
problem in swing-awtproblem 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 AWTproblem 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 AWTJava
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 AWTMultiple 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 AWTJfree 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 AWTJava 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
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 New Problem in Form Resizing - Swing AWTNew
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 AWTProblem 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
AWT & SWINGAWT & SWING What is diffennce between
AWT &
SWING swing-awt - Swing AWTswing-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 AWTswing/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
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 AWTAWT 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 AWTjava
swing awt thread query Hi, I am just looking for a simple example of Java
Swing awt swings - Swing AWTawt 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 AWTjava 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 AWTSwing 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 AWTjava
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 AWTjava 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 - Swing AWTSWING 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 AWTjava
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 AWTswing 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 - Swing AWTSWING 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 AWTSwing 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 AWTswing 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
AWT-swings tutorial - Swing AWTAWT-swings tutorial hello sir,
i am learnings swings and applets.. i want some tutorials and some examples related to swings..
thank you sir...://www.roseindia.net/java/example/java/
swing/
http://www.roseindia.net/java/example/java
SWINGS - Swing AWT more information,Examples and Tutorials on
Swing,
AWT visit to :
http://www.roseindia.net/java/example/java/
awt/
http://www.roseindia.net/java/example/java/
swing/
Thanks
code - Swing AWTcode i want example
problem for menubar in swings Hi Friend,
Please visit the following links:
http://www.roseindia.net/java/example/java/
swing/SwingMenu.shtml
http://www.roseindia.net/java/example/java/
swing Java - Swing AWTJava program to read,add,update,delete the database using
swing and servlet Hello
Just Refer Don't Copy the content of this URL... the
problem to visit......
http://roseindia.net/servlets/web-application.shtml
awt list item* - Swing AWTawt list item* how do i make an item inside my listitem not visible Hi friend,
import java.awt.*;
import java.awt.event.... information.
http://www.roseindia.net/java/example/java/
awt/
Thanks
AWT code for popUpmenu - Swing AWTAWT code for popUpmenu Respected Sir/Madam,
I am writing a program in JAVA/AWT.My requirement is, a Form consists of a "TextBox" and a "Button... for more information.
http://www.roseindia.net/java/example/java/
awt/pop
Image Manipulation in Swing AWTImage Manipulation in
Swing AWT Sir,
I'am new to
Swing Programming. I have to create an application where an image is displayed on one Label... with this
problem. It's urgent since I have to submit my project within a week
Java Dialogs - Swing AWT visit the following links:
http://www.roseindia.net/java/example/java/
swing/GrideComponents.shtml
http://www.roseindia.net/tutorial/java/
swing/springlayout.html
http://www.roseindia.net/java/example/java/
awt/borderlayout-example
Combobox application - Swing AWTCombobox application hi, i am facing a
problem in updation of the comboboxes i m using in an application...for the first time the selectec item does... function...please suggest... Is it
Swing ?
If not using
Use of Hyperlink in Swing - Swing AWTUse of Hyperlink in Swing Hi,
We are developing the UI using the Java
Swing and I have to create Hyperlink in the JTable cell so that if the user... is:
Is it possible to use Hypelink in java
Swing.
Please Help.
Regards
validating - Swing AWTvalidating hi another
problem i am facing in
swing is that is
i have got many textfeilds
ex:
Roll No:
Name:
Address:
so
Roll No TextField have to Contains only Numbers.
Name TextFields have to contain only
Java - Swing AWTJava write a
swing program to display the contents of a database in a JTable
Swing Problem on submission of buttonSwing Problem on submission of button How to close current frame (Frame1) and open a new frame (Frame2) already created and pass the data to frame2 from frame1 on the clicking of button in
swing tree - Swing AWT visit the following code:
http://www.roseindia.net/java/example/java/
swing/TreeComponent.shtml
http://www.roseindia.net/java/example/java/
swing/AddNodes.shtml
http://www.roseindia.net/java/example/java/
swing/RemoveNodes.shtml
Thanks
java-swings - Swing AWTjava-swings How to move JLabel using Mouse?
Here the
problem is i have a set of labels in a panel. I want to arrange them in a customized order...://www.roseindia.net/java/example/java/
swing/
Thanks.
Amardeep
provide code - Swing AWTprovide code Dear frnds please provide code for two player CHESS GAME.....using swings,
awt concepts
Hi friend,
import java.awt..../java/
swing/
Thanks
Java swing in NetBeans - Swing AWTJava
swing in NetBeans thanks a lot sir for everything you answered for my last questions now sir i just have another 3 questions that is
Q 1.
i will specify a
swing code for JTable using NETBEANS so would you tell me