Java Forums

Main Menu
Home
Today's Posts
FAQ
Search
Contact Us

Java Network
Linux Archive
Java Tips
Java Tips Blog

Sponsored Links





Welcome to the Java Forums.

You are currently viewing our boards as a guest which gives you limited access to view most discussions and access our other features. By joining our free community, you will:

  • have access to post topics
  • communicate privately with other members (PM)
  • not see advertisements between posts
  • have the possibility to earn one of our surprises if you are an active member
  • access many other special features that will be introduced later.

Registration is fast, simple and absolutely free so please, join our community today!

If you have any problems with the registration process or your account login, please contact us.

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 05-21-2008, 03:53 AM
Member
 
Join Date: May 2008
Posts: 5
supa_kali_frajilistik is on a distinguished road
calling a public void method from a class button
hi guys i am working on swing classes, and what i am trying to do is call the printData() class and its method printStuff() from a touch of a button but when i excute it i get an error...can any body help me out or give me some advice....i will appreciate any help given ....tc

Code:
class Printdata2{ public Printdata2() { try { // Connect to the Database //connection object created using DriverManager class //carpark is the name of the database Class.forName("sun.jdbc.odbc.JdbcOdbcDriver"); Connection connect =DriverManager.getConnection("jdbc:odbc:carpark"); // Read data from a table String sql = "SELECT * FROM Ticket"; Statement stmt = connect.createStatement(); String linebreak = System.getProperty("line.separator"); ResultSet rset = stmt.executeQuery("SELECT tnum, timein, timeout FROM Ticket"); String str = ""; while (rset.next()) { str += linebreak + "Ticket Number: "+ rset.getObject(1)+ linebreak +"Customer Time In: "+ rset.getObject(2)+ linebreak +"Customer Time Out: "+ rset.getObject(3)+ linebreak+ linebreak; } byte buf[] = str.getBytes(); OutputStream fp = new FileOutputStream("tickets.txt"); fp.write(buf); fp.close(); rset.close(); stmt.close(); connect.close(); } catch(Exception e) { e.printStackTrace(); } } public static void main(String args[]) throws Exception { Printdata2 fr = new Printdata2(); } public void printStuff(String args[]) throws Exception{ String filename = ("tickets.txt"); // THIS IS THE FILE I WANT TO PRINT PrintRequestAttributeSet pras = new HashPrintRequestAttributeSet(); DocFlavor flavor = DocFlavor.INPUT_STREAM.AUTOSENSE; // MY FILE IS .txt TYPE PrintService printService[] = PrintServiceLookup.lookupPrintServices(flavor, pras); PrintService defaultService = PrintServiceLookup.lookupDefaultPrintService(); PrintService service = ServiceUI.printDialog(null, 200, 200, printService, defaultService, flavor, pras); if (service != null) { DocPrintJob job = service.createPrintJob(); FileInputStream fis = new FileInputStream(filename); DocAttributeSet das = new HashDocAttributeSet(); Doc doc = new SimpleDoc(fis, flavor, das); job.print(doc, pras); Thread.sleep(10000); } } }
this class or button that i want to call class Printdata() and its method printStuff()..

Code:
class B8 implements ActionListener { public void actionPerformed(ActionEvent e) { Printdata2 frame = new Printdata2(); Printdata2.printStuff(); }





the errors i get are below:::::

Code:
C:\Users\omar\Desktop>javac JFrameApplication.java JFrameApplication.java:130: printStuff(java.lang.String[]) in Printdata2 cannot be applied to () Printdata2.printStuff(); ^ Note: JFrameApplication.java uses or overrides a deprecated API. Note: Recompile with -Xlint:deprecation for details. Note: JFrameApplication.java uses unchecked or unsafe operations. Note: Recompile with -Xlint:unchecked for details. 1 error C:\Users\omar\Desktop>
Bookmark Post in Technorati
Reply With Quote
Sponsored Links
  #2 (permalink)  
Old 05-21-2008, 07:38 AM
sukatoa's Avatar
Senior Member
 
Join Date: Jan 2008
Location: Cebu City, Philippines
Posts: 527
sukatoa is on a distinguished road
Send a message via Yahoo to sukatoa
It says that you have to pass an array of Strings in printStuff() method when invoking on it....

try to compile those java files with -Xlint,
a detailed info should be there and guide you where are those warnings came from....
__________________
A specific, detailed, simple, well elaborated, and "tested before asking" question may gather more quick replies. hopefully
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
Bookmark Post in Technorati
Reply With Quote
  #3 (permalink)  
Old 05-21-2008, 02:40 PM
Member
 
Join Date: May 2008
Posts: 5
supa_kali_frajilistik is on a distinguished road
heres the error i get ....

Code:
C:\Documents and Settings\10294455\Desktop>javac JFrameApplication.java -Xlint frame.printStuff(); ^ 1 error C:\Documents and Settings\10294455\Desktop>
Bookmark Post in Technorati
Reply With Quote
  #4 (permalink)  
Old 05-21-2008, 04:21 PM
Member
 
Join Date: May 2008
Posts: 5
supa_kali_frajilistik is on a distinguished road
i got it working !!!! theres only one problem see below.....


Code:
class B8 implements ActionListener { public void actionPerformed(ActionEvent e) { Printdata2 frame = new Printdata2(); }

Code:
class Printdata2{ public Printdata2() { try { // Connect to the Database //connection object created using DriverManager class //carpark is the name of the database Class.forName("sun.jdbc.odbc.JdbcOdbcDriver"); Connection connect =DriverManager.getConnection("jdbc:odbc:carpark"); // Read data from a table String sql = "SELECT * FROM Ticket"; Statement stmt = connect.createStatement(); String linebreak = System.getProperty("line.separator"); ResultSet rset = stmt.executeQuery("SELECT tnum, timein, timeout FROM Ticket"); String str = ""; while (rset.next()) { str += linebreak + "Ticket Number: "+ rset.getObject(1)+ linebreak +"Customer Time In: "+ rset.getObject(2)+ linebreak +"Customer Time Out: "+ rset.getObject(3)+ linebreak+ linebreak; String filename = ("tickets.txt"); // THIS IS THE FILE I WANT TO PRINT PrintRequestAttributeSet pras = new HashPrintRequestAttributeSet(); DocFlavor flavor = DocFlavor.INPUT_STREAM.AUTOSENSE; // MY FILE IS .txt TYPE PrintService printService[] = PrintServiceLookup.lookupPrintServices(flavor, pras); PrintService defaultService = PrintServiceLookup.lookupDefaultPrintService(); PrintService service = ServiceUI.printDialog(null, 200, 200, printService, defaultService, flavor, pras); if (service != null) { DocPrintJob job = service.createPrintJob(); FileInputStream fis = new FileInputStream(filename); DocAttributeSet das = new HashDocAttributeSet(); Doc doc = new SimpleDoc(fis, flavor, das); job.print(doc, pras); Thread.sleep(10000); } } } byte buf[] = str.getBytes(); OutputStream fp = new FileOutputStream("tickets.txt"); fp.write(buf); fp.close(); rset.close(); stmt.close(); connect.close(); } catch(Exception e) { e.printStackTrace(); } } public static void main(String args[]) throws Exception { Printdata2 fr = new Printdata2(); }

i wrote this bit of code in constructer bit and deleted printStuff().. but when the code reaches this bit of code it executes, and does'nt stop excuting it...

Code:
String filename = ("tickets.txt"); // THIS IS THE FILE I WANT TO PRINT PrintRequestAttributeSet pras = new HashPrintRequestAttributeSet(); DocFlavor flavor = DocFlavor.INPUT_STREAM.AUTOSENSE; // MY FILE IS .txt TYPE PrintService printService[] = PrintServiceLookup.lookupPrintServices(flavor, pras); PrintService defaultService = PrintServiceLookup.lookupDefaultPrintService(); PrintService service = ServiceUI.printDialog(null, 200, 200, printService, defaultService, flavor, pras); if (service != null) { DocPrintJob job = service.createPrintJob(); FileInputStream fis = new FileInputStream(filename); DocAttributeSet das = new HashDocAttributeSet(); Doc doc = new SimpleDoc(fis, flavor, das); job.print(doc, pras); Thread.sleep(10000); }
Bookmark Post in Technorati
Reply With Quote
  #5 (permalink)  
Old 05-23-2008, 03:05 PM
Member
 
Join Date: May 2008
Posts: 5
supa_kali_frajilistik is on a distinguished road
i solved it thax ...aniwais
Bookmark Post in Technorati
Reply With Quote
Sponsored Links
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
calling a public void method from a class button supa_kali_frajilistik AWT / Swing 1 05-21-2008 07:40 AM
Calling a method in another class uncopywritable New To Java 8 01-14-2008 06:37 PM
Calling method from another class asahli New To Java 1 12-15-2007 08:24 PM
public method dirtycash New To Java 4 11-21-2007 09:29 PM


All times are GMT +3. The time now is 03:27 PM.


VBulletin, Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO ©2007, Crawlability, Inc.
Copyright ©2006 - 2007, www.java-forums.org