Results 1 to 2 of 2
Thread: Dialog typeface outside Java
- 11-18-2007, 04:09 PM #1
Member
- Join Date
- Nov 2007
- Posts
- 2
- Rep Power
- 0
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
- 11-19-2007, 07:35 AM #2
Member
- Join Date
- Nov 2007
- Posts
- 2
- Rep Power
- 0
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:
This is a complete program for that purpose, which should work, but it doesn't. Can you please help me and tell me why?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); } } }
Similar Threads
-
Example of SWT Dialog
By Java Tip in forum Java TipReplies: 0Last Post: 01-09-2008, 12:01 PM -
I'm trying to add a separate dialog to a Java program...
By romina in forum AWT / SwingReplies: 1Last Post: 08-07-2007, 05:26 AM -
Dialog Box
By uncopywritable in forum New To JavaReplies: 2Last Post: 07-30-2007, 12:42 PM -
Java Print Dialog Framework 1.7
By levent in forum Java SoftwareReplies: 0Last Post: 06-19-2007, 05:07 PM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks