Results 1 to 2 of 2
  1. #1
    Dreen is offline Member
    Join Date
    Nov 2007
    Posts
    2
    Rep Power
    0

    Default Dialog typeface outside Java

    Hello Java Community,

    I am quite new to the Java language, however Im familiar with programming overall. I am in need to write an application that would use Java's Dialog typeface in image creation, but I do not know Java well enough to write it in this language.
    I am looking for the Dialog typeface in TrueType, FreeType or some other format that I would be able to use outside the Java language. I have searched for this a lot but with no results.
    I would greatly appreciate any help in finding this typeface.

    ~Dreen

  2. #2
    Dreen is offline Member
    Join Date
    Nov 2007
    Posts
    2
    Rep Power
    0

    Lightbulb

    I have decided searching is pointless, there is no Dialog outside Java.
    Being however in need as I am, I have decided to try and write a Java program, which would do what I want which is:
    * take 2 arguments in cmd line - label text and label name (label, labelName)
    * create an image with black background and white text in Dialog size 11 saying exactly what was given in label text parameter
    * save an image as labelName.png

    So far this is what I was able to produce:
    Java Code:
    public class Main {
        
        /**
         * Installation folder
         */
        static String pmDir = "/home/dreen/Makra/patmaker/";
        
        /**
         * PATs folder
         */
        static String patDir = "/home/dreen/Makra/";//matchItems/";
        
        /**
         * Font size
         */
        static int fSize = 11;
        
        
        
        
        
        
        /**
         * @param args the command line arguments
         */
        public static void main(String[] args) {
            
            // there have to be 2 arguments: label text, label name.
            if (args.length < 2)
            {
                System.out.println("Too few arguments (2 required).");
                System.exit(-1);
            }
            
            String label = args[0];
            String labelName = args[1];
            int imgH = fSize;
            int imgW = label.length() * 10; // how to get text size before initializing the image btw?
            
            // setup the image
            BufferedImage image = new BufferedImage(imgW, imgH, BufferedImage.TYPE_INT_RGB);
            Graphics2D g2d = image.createGraphics();
            
            g2d.setColor(Color.BLACK);
            g2d.drawRect(0,0,imgH,imgW);
            
            g2d.setColor(Color.WHITE);
            Font f = new Font("Dialog", Font.PLAIN, fSize);
            g2d.setFont(f);
            g2d.drawString(label, 0, 0);
            
            g2d.dispose();
            
            // save the image
            File file = new File(patDir + labelName + ".png");
            try
            {
                ImageIO.write(image,"png",file);
            }
            catch(IOException e)
            {
                handleException(e);
            }
        }
        
        
        /**
         * Handle errors
         */
        public static void handleException (Exception e)
        {
            try
            {
                BufferedWriter errorLog = new BufferedWriter(new FileWriter(pmDir + "error.log"));
                errorLog.write("Afollowing error occured:\n\n");
                errorLog.write ("====== Exception " + e.getMessage() + " ======");
                errorLog.write(e.getStackTrace().toString());
                System.err.println("An error occured, log file saved.");
                System.exit(-1);
            } catch(IOException ioe) 
            {
                System.err.println("IOException");
                System.exit(-1);
            }
            
        }
    }
    This is a complete program for that purpose, which should work, but it doesn't. Can you please help me and tell me why?

Similar Threads

  1. Example of SWT Dialog
    By Java Tip in forum Java Tip
    Replies: 0
    Last Post: 01-09-2008, 01:01 PM
  2. Replies: 1
    Last Post: 08-07-2007, 06:26 AM
  3. Dialog Box
    By uncopywritable in forum New To Java
    Replies: 2
    Last Post: 07-30-2007, 01:42 PM
  4. Java Print Dialog Framework 1.7
    By levent in forum Java Software
    Replies: 0
    Last Post: 06-19-2007, 06:07 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •