My java code doesn't work the way it should

Hello can someone tell me why this code isn't printing on my linux computer?
I found something about a bug in java for printing with linux see link.
http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=6181488
I hope someone can help me.
import javax.print.*;
import javax.print.attribute.*;
import java.io.*;
import java.awt.BasicStroke;
import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Component;
import java.awt.Container;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.RenderingHints;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.geom.CubicCurve2D;
import java.awt.print.PageFormat;
import java.awt.print.Printable;
import javax.print.Doc;
import javax.print.DocFlavor;
import javax.print.DocPrintJob;
import javax.print.PrintException;
import javax.print.PrintService;
import javax.print.PrintServiceLookup;
import javax.print.SimpleDoc;
import javax.print.attribute.DocAttributeSet;
import javax.print.attribute.HashDocAttributeSet;
import javax.print.attribute.HashPrintRequestAttributeSet;
import javax.print.attribute.PrintRequestAttributeSet;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JPanel;
public class PrintingOneTwoFour {
   static class MyComponent extends JPanel implements Printable {
     public void paint(Graphics g) {
       Graphics2D g2d = (Graphics2D) g;
       g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
           RenderingHints.VALUE_ANTIALIAS_ON);
       g2d.setPaint(Color.BLUE);
       g2d.setStroke(new BasicStroke(3));
       CubicCurve2D cubic = new CubicCurve2D.Float(10, 80, 60, 30, 110, 130, 160, 80);
       g2d.draw(cubic);
     public int print(Graphics g, PageFormat pageFormat, int pageIndex) {
       if (pageIndex == 0) {
         paint(g);
         return Printable.PAGE_EXISTS;
       } else {
         return Printable.NO_SUCH_PAGE;
   public static void main(String args[]) throws Exception {
     final JFrame frame = new JFrame();
     Container contentPane = frame.getContentPane();
     final Component printIt = new MyComponent();
     contentPane.add(printIt, BorderLayout.CENTER);
     JButton button = new JButton("Print");
     contentPane.add(button, BorderLayout.SOUTH);
     ActionListener listener = new ActionListener() {
       public void actionPerformed(ActionEvent e) {
         DocFlavor flavor = DocFlavor.SERVICE_FORMATTED.PRINTABLE;
      //      PrintService printService = PrintServiceLookup
         //     .lookupDefaultPrintService();
      PrintService[] services  = null;
         PrintService   myPrinter = null;
      //   DocFlavor myFlavor = DocFlavor.INPUT_STREAM.POSTSCRIPT;
         PrintRequestAttributeSet jobAttrs = new HashPrintRequestAttributeSet();
         services = PrintServiceLookup.lookupPrintServices( flavor, jobAttrs );
if ( System.getProperty( "os.name" ).startsWith( "Windows" ) )
    myPrinter = PrintServiceLookup.lookupDefaultPrintService();
  else {
    try { 
        Process child = Runtime.getRuntime().exec(new String[] { "/bin/sh", "-c", "echo ${PRINTER:-$LPDEST}" });
        BufferedReader rdr = new BufferedReader(new InputStreamReader( child.getInputStream() ));
        String envPrinter = rdr.readLine().trim();
        System.out.println("Printer "+envPrinter+rdr.readLine());
     child.destroy();
        for ( int i=0; myPrinter == null && i<services.length; i++ )
            if ( services.getName().equals( envPrinter ) )
myPrinter = services[i];
          System.out.println("myPrinter "+myPrinter);
catch ( Exception ignore )
System.out.println("Exception "+ignore);
if(myPrinter==null)     
myPrinter = services[0];
System.out.println("myPrinter == null "+myPrinter);
     DocPrintJob job = myPrinter.createPrintJob();
DocAttributeSet das = new HashDocAttributeSet();
Doc doc = new SimpleDoc(printIt, flavor, das);
try {
job.print(doc, jobAttrs);
} catch (PrintException pe) {
pe.printStackTrace();
button.addActionListener(listener);
frame.setSize(350, 350);
frame.show();

Nobody????????????

Similar Messages

  • Facetime doesn't work the way it should...

    Unfortunately, since I arrived back home in Germany Facetime stopped working they way it has been before.
    I was visiting my Boyfriend on the other side of the world and for us, Facetime is one of the most important things.
    My Wifi at home is still the same and his situation didn't change either.
    When I call, I can hear the ringtone Facetime makes, when he is picking up. I can also hear some background noises and with a little luck I can also hear him saying something. But after 5 seconds (the latest) everything breaks down kind of. I can't hear anything at all anymore. Just from time to time there are backgroundnoises but after a short time they disappear again.
    Both of us have an Iphone 5 and both of us have IOS 8 installed.
    It would be nice to know why it stopped working in the first place. If nothing happens we will have to switch to skype, which would be sad, because the connection with facetime has always been really good - just like a real call.
    Hoping for help
    Hannah

    The first step would be to try and FaceTime someone else to see if you have the same issue. If so, try to reset  your iPhone by holding down the home and lock buttons until you see the Apple Logo. If you are able to use FaceTime with someone else then it could be on your boyfriend's end. Possibly have him reset his iPhone as well.
    If none of that works, consider finding a boyfriend that you are able to FaceTime with.

  • Code doesn't behave the way it should when i create an ipa . However , if i flash the build directly from xcode it works fine ?

    Hi ,
    I am creating an ipad application . When the app launches i am trying to get some data from server , and show it at the beggining .
    It works perfectly fine when i run the app in simulator , and flash the build in ipad from Xcode .
    However ,as soon i create an ipa file , install in ipad it doesnt works . Sometimes , it shows network issue , other times its able to give me the data but as soon i convert the data to JSON objet with NSJSONSerialization class , it returns nill .
    Any clue on this abrupt issue ??

    Hi,
    Are you loading the data in didFinishLaunching ??
    If yes then that is the problem.
    ios defines a specific time for app launch, if your app takes more than the allowed time, ios will crash the app.
    Possible solution might be move the webservice call from there to some other suitable place, this will ensure that you app will launch regardless of any network issue, which can be handled later.

  • Ps 3d and filters and save for web are not working the way they should

    At work we just put cs6 on a w7 machine running 64 bit which has more than that required mem and or ram to run cs6 - unfortunately I have to use a windows based machine at work (cheapskates). Anyways. I see the 3d menus and the filter menu in PS but they aren't funtional. The filter menu drop down is there but Liquify is the only one that shows up the rest are gray. The option to choose 3d is also there but they are not functional (grayed out) - I took a look at some online tutorials on using the 3d effect in PS CS6 and Ive gone through it a few times and it still won't work for me. Also, in illustrator when I save for web - when I adjust the pixel dimensions and move the mouse over and click on the image that I am saving for web nothing happens and I'm completely boggled about how to get the image size to change in the save for web pane. Typically I am used to being able to input the the number into the pixel dimenion field and click on the image and the image resizes (on a mac you can either click on the image or hit return and the image will resize in front of your eyes!). I am unable to get this to work the way I am used to, this happens for me in both ill5 and ill6 on this piece of crap windows machine. Maybe I just need to reinstall? Maybe adobe has changed the way this works? Maybe a sledge hammer into this windows machine would solve all my problems!? IDK. someone help... help me... pleeeeaaaaaaaaaaasssseeeee

    unfortunately I have to use a windows based machine at work (cheapskates).
    This gets a "stupid comment of the day" medal. Seriously. These days Macs are just as convoluted and effed up as Windows was a few years ago - nice as long as everything works, but god forbid you have a problem. So by all means, update your graphics driver and be glad that you actually have that choice rather than having to wait half a year for Apple to fix it...
    Mylenium

  • Why does this java code doesn't work on my pc?

    for example:
    package one;
    public class Alpha {
    //member variables
    private int privateVariable = 1;
    int packageVariable = 2; //default access
    protected int protectedVariable = 3;
    public int publicVariable = 4;
    //methods
    private void privateMethod() {
    System.out.format("privateMethod called%n");
    void packageMethod() { //default access
    System.out.format("packageMethod called%n");
    protected void protectedMethod() {
    System.out.format("protectedMethod called%n");
    public void publicMethod() {
    System.out.format("publicMethod called%n");
    public static void main(String[] args) {
    Alpha a = new Alpha();
    a.privateMethod(); //legal
    a.packageMethod(); //legal
    a.protectedMethod(); //legal
    a.publicMethod(); //legal
    System.out.format("privateVariable: %2d%n",
    a.privateVariable); //legal
    System.out.format("packageVariable: %2d%n",
    a.packageVariable); //legal
    System.out.format("protectedVariable: %2d%n",
    a.protectedVariable); //legal
    System.out.format("publicVariable: %2d%n",
    a.publicVariable); //legal
    As you can see, Alpha can refer to all its member variables and all its methods, as shown by the Class column in the preceding table. The output from this program is:
    privateMethod called
    packageMethod called
    protectedMethod called
    publicMethod called
    privateVariable: 1
    packageVariable: 2
    protectVariable: 3
    publicVariable: 4
    when above example runs on my pc:
    it works below description:
    D:\javacode>javac Alpha.java
    D:\javacode>java Alpha
    Exception in thread "main" java.lang.NoClassDefFoundError: Alpha (wrong name: on
    e/Alpha)
    at java.lang.ClassLoader.defineClass1(Native Method)
    at java.lang.ClassLoader.defineClass(Unknown Source)
    at java.security.SecureClassLoader.defineClass(Unknown Source)
    at java.net.URLClassLoader.defineClass(Unknown Source)
    at java.net.URLClassLoader.access$100(Unknown Source)
    at java.net.URLClassLoader$1.run(Unknown Source)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.net.URLClassLoader.findClass(Unknown Source)
    at java.lang.ClassLoader.loadClass(Unknown Source)
    at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
    at java.lang.ClassLoader.loadClass(Unknown Source)
    at java.lang.ClassLoader.loadClassInternal(Unknown Source)
    why it runs wrongly and who can help me?
    thanks

    if i runs it below:
    D:\javacode>javac one\Alpha.java
    D:\javacode>java one.Alpha
    privateMethod called
    protectedMethod called
    protectedMethod called
    privateVariable: 1
    packageVariable: 2
    protectedVariable: 3
    publicVariable: 4
    it runs well!

  • IMessage across multiple devices - not working the way it should?

    OK, here's the problem: I'm seeing conversations in iMessage on my iPad, but yet I'm not seeing any of those conversations on my iPod Touch.
    My guess this problem exists is because I've used a different iTunes account on my iPod Touch to experiment with iMessage between my iPod Touch and iPad. I did this before I signed in with the same iTunes account as on my iPad (my primary iTunes account), but then again, I don't event know what the problem is.

    Hi frankct,
    iMessage do work as advertise for an AppleID; i.e. all your devices will show in sync all your messages.
    For this to work like this, you obviously need to login into the same account for all your devices.  Go, in the settings of your iPod Touch in the Message section.  There, at the bottom, tap "receive at" and you will see to which account iMessage is linked.  Most probably in your case, your iPad and your iPod aren't loged into the same account.
    I haven't try it you can independently log iMessage with an AppleID different than the one use for your purchase but you could try it.
    If I may suggest; if you own your these two devices, you should chose one of your AppleID and use it only for now on.  If you don't, you nightmare will continue while you may mix other sync iCloud info and having purchased on two accounts.
    Even if you only purchase from account A from now on, you simply have to keep your devices also authorized to play your content purchased brom account B.

  • I installed the latest version AND the beta and with both I have the same problem: After I install, they both work the way they should. When I turn off my computer and get back on later, Firefox is NOT "installed", according to my computer.

    ''locking as a duplicate of this - https://support.mozilla.com/en-US/questions/791340''
    I installed the latest version first. When I was done, Firefox was working great. I got off and went back on to my computer later. Firefox was not there, but the shortcut was. I got this error that the item that referred to the shortcut was no longer there. I uninstalled. I tried the beta (4) and the same exact issue occured.

    ryansaint11,
    this isn’t Apple support; this is a user-to-user forum. We’re just fellow users of Apple products here.
    If you want to boot from your SSD, then you should put the SSD where your HDD currently is, and put the HDD into the optical bay. (That setup will also get you the best performance.) At the moment, you’re still booting from your HDD. Note that you will need to format your SSD in Disk Utility [with the “Mac OS X Extended (Journaled)” format] so that you can install OS X onto it.
    Since you have an Early 2011 model, it might or might not have originally come with grey installation DVDs. You will be able to find out whether it did or not by trying to use OS X Internet Recovery to install OS X onto your SSD. If it does not work, or if the installed OS turns out to be Snow Leopard, then it will have originally come with the DVDs, and you should purchase a replacement pair of DVDs from Apple or iFixit; those discs will have your MacBook Pro’s Apple Hardware Test and its iLife apps. If the installed OS turns out to be Lion, then it will not originally have come with the grey installation DVDs, and your Apple Hardware Test will be installed along with Lion, and your iLife apps will be downloadable from the Mac App Store.

  • GTX 970 not working the way it should.

    Hello, I bought a msi gtx 970 yesterday but it is not working good. I can not even play league of legends without stuttering. When I play on maximum settings it says 60 fps, but in fact it is stuttering. The memory clock keeps shooting up to 3506 and than goes down again, this keeps happening. When I had call of duty advanced warfare open for 10 minutes, not even being in a game, the gpu usage is 98% and the memory use is extremely high, while nothing is happening on the screen, just some menus.
    All drivers are downloaded and previous drivers from my old video card are removed.
    These are my pc specs.
    i5 760 @ 2,8 GHz
    msi gtx 970
    8gb DDR3 RAM
    Asustek V-P7H55E motherboard
    Windows 8.1 64 bit
    Hope someone can help me out.

    Quote from: Nichrome on 09-February-15, 22:57:36
    My current 780Ti is getting bottleneck by the CPU I have.. so even worse would be if I'd have 970 or 980..
    That's because yours is the T version. It's not even nearly as good as the normal 4670 or K version.
    Actually, it the lowest of the versions. Even S version would be better.
    With normal 4670 and 4670K you wouldn't be getting bottleneck.
    Quote from: lucas-1996 on 09-February-15, 22:07:05
    I have one more question. I cant really decide if I shall get the i5-4690k for my new motherboard or the i7-4790k. Is the i7 worth the 100 euro extra? I dont do things like photoshop, maybe a bit of streaming though.
    What kind of cooling you have currently, or are you using stock cooler?
    If you don't have sufficient cooler or are running stock cooler, you will need to invest on better cooling.
    In which case, get the i5 4670K and buy a new, better cooler with that 100$.
    I would recommend at least Hydro H80i if you have a free 120mm fan slot in the case.
    If not, get the BeQuiet! Dark Rock Pro 3 or similar.

  • The ussd code doesn't work on my iphon since i update to ios 7.0.3 what can i do for this problem?

    the ussd code doesn't work on my iphon since i update to ios 7.0.3 what can i do for this problem?

    Maybe
    SOLUTION: circle with red square Some Music Won't Play After...: Apple Support Communities

  • Key-code change... from windows to mac... the old key-code doesn´t work

    I bought a CS for Windows and used it on Windows.
    Now I bought a Mac and want to use it,
    but the key-code doesn´t work.
    How can I get a key-code wich works???

    Neither the keycode nor the Windows version of the software will work on a Mac.
    You can only swap platforms for the latest version of Adobe products, which is currently CS6.
    Order product | Platform, language swap

  • Tryoing to play QVR. Works on a MAC with version 7. Doesn't work the same using Version 10.

    Have some .mov files that work just find on my MAC that has QVR player version 7. When I try these same files on a MAC that was recently updated automatically and has QVR version 10, the .mov doesn't work the same way.  Is there a way to set parameters in version 120 to behave like version 7 or alternatively can I download version 7?

    Mac OS X 10.6 includes QuickTime versions 10.0 and 7.6.3. The QuickTime 7 player will only be present if a QuickTime Pro key was present at the time of installation, or if specified as part of a custom install, or individually downloaded:
    http://support.apple.com/kb/dl923
    Snow Leopard update 10.6.4 included an update to 7.6.6 (if installed). You can install it from the above link  even though it says for 10.6.3. It's the same version of QuickTime Player 7.6.6.
    (Only QuickTime Player 7.6.3 or 7.6.6 can be updated to "Pro".)
    A Mac OS X v10.6, OS X Lion, and OS X Mountain Lion-compatible version of QuickTime Player 7 is available for use with older media or with AppleScript-based workflows. QuickTime Player 7 can be used to playback formats such as QTVR, interactive QuickTime Movies, and MIDI files. Also, it supports QuickTime 7 Pro registration codes for access to QuickTime Pro functionality.
    How to install Quicktime Player 7 on Snow Leopard, Lion and Mountain Lion when it is not already present:
    http://support.apple.com/kb/HT3678?viewlocale=en_US&locale=en_US

  • ISF/javascript code doesn't work for non-English RequestCenter proile

    ISF/javascript code doesn't work for non-English RequestCenter proile
    Hello,
    I am not sure if i posted the same question before also. We have some customers who have set thier language profile in newScale requestcenter to French. However, all the javascript customizations configured on the service forms do not function for 'French' as a Langauge preference. Has anyone encountered the similar issue before and can anyone please suggest a solution for it?
    Thanks,
    Mihir

    we had a similar issue a while back where the Approval button was not working in Spanish, needed a fix from nS for it
    The way to fix this would be to locate the language XML file, override the French caption with Submit and on onLoad write a global JS that would write the button label again (not so sure about this)
    But really its an major defect and they should be able to fix it.

  • How to use documentbeforesaved method? And why my code doesn't work in template files?

    Can someone help me with these two codes?
    ----Beginning of code 1-------------
    Private WithEvents App As Word.Application
    Private Sub Document_Open()
    Set App = Word.Application
    End Sub
    Private Sub App_DocumentBeforeSave(ByVal Doc As Document, SaveAsUI As Boolean, Cancel As Boolean)
    MsgBox("BeforeSave")
    End Sub
    --------------End of the code----------------
    Beginning of code 2--------------- Code 2 is from https://msdn.microsoft.com/en-us/library/office/ff838299(v=office.15).aspx
    Public WithEvents appWord as Word.Application 
    Private Sub appWord_DocumentBeforeSave _ 
     (ByVal Doc As Document, _ 
     SaveAsUI As Boolean, _ 
     Cancel As Boolean) 
     Dim intResponse As Integer 
    Private Sub App_DocumentBeforeSave(ByVal Doc As Document, SaveAsUI As Boolean, Cancel As Boolean)
    MsgBox("BeforeSave")
    End Sub
    In the first code, they have:
    Private Sub Document_Open()
    Set App = Word.Application
    End Sub
     I test these two codes in "This document" object, and I find out the first code works but the second code are not!
    Why second code doesn't work?
    Extra question: I am using microsoft 2013. I insert this code into a macro-enabled template. But when I am about to save my file I am expecting these code works. However, they didn't work!
    Thank you for solving these problem for me!

    Hello,
    Please note that the code snippet 2 in your post is different from the code snippet in the MSDN document. Also please read the comments of the MSDN code sample:
    This example prompts the user for a   yes or no response before saving any document.
    This code must be placed in a   class module, and an instance of the class must be correctly initialized to   see this example work; see
    Using Events with the Application Object for   directions on how to accomplish this.
    Public WithEvents appWord   as Word.Application
    Private Sub   appWord_DocumentBeforeSave _
     (ByVal Doc As Document, _
     SaveAsUI As Boolean, _
     Cancel As Boolean)
     Dim intResponse As Integer
     intResponse = MsgBox("Do you really   want to " _
     & "save the document?", _
     vbYesNo)
     If intResponse = vbNo Then Cancel = True
    End Sub
    So the problem in your code snippet 2 is that you didn't put it into a class module and initialize the class module. If you just put it into ThisDocument, you have to initialize the word application object.
    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click
    HERE to participate the survey.

  • Code Doesn't work although it works on DEV

    hello evey body
    some functions and codes doesn't work on application server But it works on developer ??!!
    as i have code to export data from oracle to excell . it works from developer but it doesn't from application server
    this is my code in the link
    http://www.4shared.com/document/7wTQrK1-/Excell_Rep.html
    does Application Server didn't contain this packages ?
    or what ??

    Hi dorpfeld,
    Please check the KB : http://helpx.adobe.com/creative-suite/kb/error-serial-number-valid-product.html
    I would strongly recommend that you work directly with our support team for serial number issues.
    You can reach our chat support for serial number issues at : http://adobe.ly/1aYjbSC
    Regards,
    Rave

  • Mountain lion redeem code doesn't work!!!

    Mountain lion redeem code doesn't work!!!

    The codes got sent out pre-maturely on the 23rd to some folks. And now on the go-live those codes have been re-used.
    https://discussions.apple.com/message/19014392?ac_cid=tw123456#19014392
    In short - wait for a new email from apple.

Maybe you are looking for

  • Skype 4.2.0.11 has abnormally high CPU usage while...

    Skype 4.2.0.11 has abnormally high CPU usage while idle. I can't get my laptop under 70 degrees celsius unless I cpulimit or quit skype, and cpulimiting it actually makes it completely unresponsive, as if some other thread is constantly generating a

  • SDK 2005

    Hi, im looking for the 2005A Business One SDK, which contains the samples. Specially i am looking for the 17.ChooseFromList sample. Does someone know the link to the sdk samples. Thx for help.

  • How to remove the application which is downloaded from app store

    I have downloaded pocket pond application from app store. However I would like to remove it as I do not like it. Can you let me know how to remove the application? Regards AADK

  • Firefox disappered from my desk top -it will not come back after new download, help

    I got reminders of new updates. I tried several times but it never completed the process after a huge time lapse. Now it disappeared from my icons and could not be retrieved so I tried to download Firefox again. It appears to download ..then nothing.

  • ITunes error -9813

    I updated to the iTunes 8.2 (23) and then tried to update my iPhone to OS 3.0. The OS didn't install so my phone doesn't work and when I connect it to iTunes I get the following error: We could not complete your iTunes Store request. An unknown error