Swing and AWT Problem

Ads

 
 
 

Share on Google+Share on Google+

swebert
Swing and AWT Problem
0 Answer(s)      7 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
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



Ads
View Answers
Ads









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
Advertisements
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
Frame refresh problem - Swing AWT
to correct this problem....its urgent!! thnks in adv..  Hi Friend
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
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
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 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
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   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 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
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 - Swing 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 - 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 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
Tutorials   
Java Spring Hibernate Struts Training Change JPanel background color from mouse entered/exit event JTable Pagination Jcombobox JAVA SWING how can i display a pdf file in a jtextarea Crop Image Code in Applet Crop Image Code in Applet Image Manipulation in Swing AWT Applet Ho to get virtual key code. how to show set of images continously using JScrollpane in java how to show set of images continously using JScrollpane in java How to connect on screen keyboard to system. How to connect on screen keyboard to system. query java client server program for playing video file(stored in folder in the same workspace) using swings java client server program for playing video file(stored in folder in the same workspace) using swings java client server program for playing video file(stored in folder in the same workspace) using swings java client server program for playing video file(stored in folder in the same workspace) using swings Download. how to open one Jframe from main method call Urgent requirement display shapes i am getting an error in adding a menu item to a menu. I am trying to develop a Image Sliding application but unfortunately its not working... Can any one help me in this Sliding window protocol how to update the value of jslider how to update the value of jslider how to update the value of jslider how to update the value of jslider how to update the value of jslider Jbutton in JTable cells program code java textfield problem swing retrieve data from database in java swing form using prev n next buttons retrieve data from database in java swing form using prev n next buttons How to close a frame on action event of a button from a different class ? searching the data swings for webnms Jpanel allignment pass data from java frame to file code for traffic control system simulation Bank Management System how to maKE Jcombox editable after saveing value init. i havei) aJTextField and one button. when place the cursor or enter anything in the test field then only button should be enabled.by default the button should be disabled. i havei) a jtable with few cloumns and few rows andii) one button. when place the cursor in any of the table's column cell. i need to enable the button.by default the button should be disabled. PDF Comparator i have JTextfield and JComboBox. there are several values in combobox.when i select a value from combobox how to make textfiled as a combobox. issue on jcombobox

Ads

 
Advertisement null

Ads