Opening java files to GUI

I am creating a program to open a java file to the GUI
I want to have a filechooser which will open the file to a text display of the GUI. How do i get to open the file and the display goes to the Text area (GUI).

import java.awt.*;
import javax.swing.*;
import java.io.*;
import java.awt.event.*;
public class Frame1
    extends JFrame {
  JPanel panel1 = new JPanel();
  BorderLayout borderLayout1 = new BorderLayout();
  JMenuBar jMenuBar1 = new JMenuBar();
  JMenu jMenu1 = new JMenu();
  JMenuItem jMenuItem1 = new JMenuItem();
  JScrollPane jScrollPane1 = new JScrollPane();
  JTextArea jTextArea1 = new JTextArea();
  JMenuItem jMenuItem2 = new JMenuItem();
  public Frame1(String title) {
    super(title);
    try {
      jbInit();
      pack();
    catch (Exception ex) {
      ex.printStackTrace();
  public Frame1() {
    this("");
  private void jbInit() throws Exception {
    panel1.setLayout(borderLayout1);
    jMenu1.setMnemonic('F');
    jMenu1.setText("File");
    jMenuItem1.setMnemonic('O');
    jMenuItem1.setText("Open");
    jMenuItem1.addActionListener(new Frame1_jMenuItem1_actionAdapter(this));
    jTextArea1.setText("jTextArea1");
    jMenuItem2.setMnemonic('E');
    jMenuItem2.setText("Exit");
    jMenuItem2.addActionListener(new Frame1_jMenuItem2_actionAdapter(this));
    getContentPane().add(panel1);
    panel1.add(jScrollPane1, BorderLayout.CENTER);
    jScrollPane1.getViewport().add(jTextArea1, null);
    jMenuBar1.add(jMenu1);
    jMenu1.add(jMenuItem1);
    jMenu1.add(jMenuItem2);
    setJMenuBar(jMenuBar1);
    setDefaultCloseOperation(JDialog.EXIT_ON_CLOSE);
  public static void main(String[] args) {
    Frame1 f = new Frame1();
    f.setLocation(50, 50);
    f.setSize(new Dimension(640, 480));
//    dlg.pack();
    f.show();
  void jMenuItem2_actionPerformed(ActionEvent e) {
    System.exit(0);
  void jMenuItem1_actionPerformed(ActionEvent e) {
    JFileChooser jfc = new JFileChooser(System.getProperty("user.home"));
    jfc.setFileFilter(
        new javax.swing.filechooser.FileFilter() {
       * Whether the given file is accepted by this filter.
      public boolean accept(File f) { return f.isDirectory() || f.getName().endsWith("java"); }
       * The description of this filter. For example: "JPG and GIF Images"
       * @see FileView#getName
      public String getDescription() { return "Java sourcer file (*.java)"; }
    jfc.showOpenDialog(this);
    File f = jfc.getSelectedFile();
    if (f != null) {
      FileInputStream fis = null;
      byte[] buf = null;
      try {
        fis = new FileInputStream(f);
        buf = new byte[fis.available()];
        fis.read(buf);
        jTextArea1.setText(new String(buf));
        jTextArea1.setCaretPosition(0);
      catch (Exception ex) {
        JOptionPane.showMessageDialog(this, ex.toString(), "Error Reading File", JOptionPane.ERROR_MESSAGE);
      finally {
        if (fis != null) {
          try {
            fis.close();
          catch (IOException ex1) {
class Frame1_jMenuItem2_actionAdapter
    implements java.awt.event.ActionListener {
  Frame1 adaptee;
  Frame1_jMenuItem2_actionAdapter(Frame1 adaptee) {
    this.adaptee = adaptee;
  public void actionPerformed(ActionEvent e) {
    adaptee.jMenuItem2_actionPerformed(e);
class Frame1_jMenuItem1_actionAdapter
    implements java.awt.event.ActionListener {
  Frame1 adaptee;
  Frame1_jMenuItem1_actionAdapter(Frame1 adaptee) {
    this.adaptee = adaptee;
  public void actionPerformed(ActionEvent e) {
    adaptee.jMenuItem1_actionPerformed(e);
}

Similar Messages

  • Open java files in Jdeveloper

    Hi,
    Good day
    I have a question about OAF under Oracle ERP version 11.10.5.2
    I have some web pages working fine, and I can see the code in the server (in the custom application folder under java). How can I open them in my client? If I open them in the JDeveloper they appear under miscellaneous node not under a workspace or a project. How can I do that?

    Dear All,
    I am not really sure which file i should open first? the Controller, Application module, Entity object or View object?
    or I need to open another file?
    Thanks for the help

  • Open .java file in already open JDeveloper

    Is there a way to force JDeveloper to open all source files in only one JDeveloper window? I am working on a project and every once in a while I download a java source sample from the web. It would be good that instead of JDeveloper opening a brand new window, it would just add it to the Miscellaneous Files branch in the already open JDeveloper window.
    Thanks in advanced for any suggestions. Hopefully there is another way than having to save the file to disk and then going through JDeveloper's import menu.

    See...
    Associating .java files with JDeveloper in Windows
    for more details.

  • How to open java files in a java project

    hi ,
    i have to implement a java program analyzer and now i have implement a java parser using javaCC. My parser parse a java file at a time and i have to read and parse all java files in a java project. my idea is to enter
    java project name *.jpx as an input and search java files in project and parse them one by one, or , to enter the folder path of java source files of project and parse them.
    i am a beginer of java language and i don't know where to start to do it.
    is there someone tell me which way is easier and better for my case and some ways to implement it. i search sample files that is similar to my case but i cannot find any.
    thanks in advance.
    ami

    if u don't mind , can u tell me which tutorial i
    should read for that? http://java.sun.com/docs/books/tutorial/essential/io/
    This... for example.
    xH4x0r

  • Open jar files through gui

    I have a program where i am trying to have a button allow the user to open a jar file from a different program and run that. Does anyone have any idea how i could go about this?
    Chris

    cmrozi1 wrote:
    First how do you search the jar file for that?You can use JarFile, its getManifest method, and Manifest to look up the value of the Main-Class attribute. If there is no Main-Class attribute in the manifest, you probably need to load each and every class file in the jar and check via reflection if the class has a main method or not.
    cmrozi1 wrote:
    I thought if its in that format it runs the file when you click it.No. This, however, is explained in the article.
    cmrozi1 wrote:
    Then second you say to use reflection to invoke the class main method. what exactly do you mean by this? do you have a tiny example?Information on reflection can be found in the Java tutorial: http://java.sun.com/docs/books/tutorial/reflect/index.html
    A tiny example:Class mainClass = ...
    try {
      final Method mainMethod = mainClass.getDeclaredMethod("main", String[].class);
      mainMethod.invoke(null, new String[0]);
    } catch (NoSuchMethodException e) {
      e.printStackTrace();
    } catch (IllegalAccessException e) {
      e.printStackTrace();
    } catch (InvocationTargetException e) {
      e.printStackTrace();
    }

  • Cannot open any Java files on my Mac OSX: Problem Solved

    Hello all,
    I have just begun an Introduction to Java class and I'm already having problems...namely, I cannot open .java files on my Mac.
    Whenever I try to open them, I get an error message that says: "You cannot use this version of the application Xcode with this version of Mac OS X."
    I'm running version 10.5.4 on a PowerPC Mac. It's a few years old, but I don't understand how it could already be so outdated as to not allow me to even use the application.
    I am 100% new to programming and don't really know at all what I'm doing. Apple says their JDK comes with every Mac and no one else seems to be having this problem. I don't really even know where to go to for updates, if that is what I need to do, or if I should just download a different JDK.
    This is an intensive (6-week) class and I don't want to fall behind, but it's halfway through the first week and I cannot even open files.
    Any suggestions greatly appreciated.
    EDIT: I figured out the problem by getting out my installation disks and I found the latest xCode tools app in the "optional packages" folder.
    Installed it and now I'm up and running.
    Edited by: chalks on Sep 17, 2008 10:09 AM

    You can download Adobe Reader from adobe.com.  The Mac OSX uses its "reader" to open PDF files without the Adobe Reader.  If you downloader adobe reader, it should open all PDF files.  Hope this helps.

  • JFileChooser problem opening just java files

    Hi everyone, trying to write simple text ed. that will only open java files (part of JFileChooser). Yes have looked at API but so stupid that i couldnt get it to work can anyone help?
    public void openFile() {
              BufferedReader in = null;
              try {
                   JFileChooser chooser = new JFileChooser();
                   //---Open Java Files only---
                   if (chooser.showOpenDialog(null)
                   == JFileChooser.APPROVE_OPTION) {
                   File selectedFile = chooser.getSelectedFile();          
                   in = new BufferedReader
                             (new FileReader(selectedFile));
         catch(FileNotFoundException e) {
              JOptionPane.showMessageDialog
                   (null, "Bad Filename. Try Again");
         catch(IOException e) {
              JOptionPane.showMessageDialog
                   (null, "Corrupted File. Try Again");
         finally {
              if (in != null)
                   try {
                        StringBuffer buffer = new StringBuffer();
                        String text = new String();
                        text_chat.setText(text + "\n\n");
                        while((text=in.readLine())!=null)
                             buffer.append(text+ "\n");
                        text_chat.setText(buffer.toString());
                   catch(IOException e) {
                        JOptionPane.showMessageDialog
                             (null, "Error closing File.");
    }

    Can you tell me how did you solve the problem? Right now I am encounter ing the same problem. The java files on JFileChooser did not show up!

  • How can I open help file (HTML or .chm) from Java Web Start (new to JAVA)

    Hi All,
    Im trying to open the help file of my application.
    When trying to access the help file from the GUI (pressing F1 for launching the help file), I'm geting the an error, something like:
    "Can't show help URL: jar:file:C:\Documents and Settings\%USER%\Application Data\Sun\Java\Deployment\javaws\cache\http\Dlocalhost\P7001\DMwebstart\RMjar-name!/com/resources/helpFiles/MyHelpFile.html"
    It seems that the file which is packed in a jar, was downloaded to the Java Web Start cache directory:
    C:\Documents and Settings\%USER%\Application Data\Sun\Java\Deployment\javaws\cache\http\Dlocalhost\P7001\DMwebstart
    The code which is activated when launching the help file is:
    try
                ResourceBundle resourceBundle = DoubleResourceBundle.getBundle("Resource", "ResourceImpl");
                RuntimeUtil.launchFile(new File(resourceBundle.getString("help.file")));
            } catch (IOException e)
                // TODO Auto-generated catch block
                e.printStackTrace();
            }where the property "help.file" is in some property file in the resource bundle named "Resource", and looks like this :
    help.file="com/trax/docs/help/global/MyHelpFile.html"
    The function "RuntimeUtil.launchFile" knows how to launch any file in its default application, and indeed it does launches the html, when giving it an absolute path to the file on my PC, as "C:\Helpfiles\MyHelpFile.html" as such:
    RuntimeUtil.launchFile("C:\Helpfiles\MyHelpFile.html");My question is :
    The application is going to be deployed on a Customer PC. How can I access the html file from the code, with a relative path and not its absolute path on the customer pc, which I can't know?
    I found these restrictions regarding web start:
    (copied from "http://rachel.sourceforge.net/"):
    *Rule 1: Java Archives only. No loose files.* All your resources have to be packaged in Java Archives (jar) if you want to have
    them delivered to the user's machine and kept up-to-date automatically by Java Web Start.
    *Rule 2: No file paths.* You can't use absolute or relative file paths to locate your
    jars holding your resources (e.g. <code>jar:file:///c:/java/jws/.cache/resources.jar</code>).
    Absolute file paths won't work because you never know where Java Web Start
    will put your jar on the user's machine. Relative file paths won't work because Java Web Start
    mangles the names of your jars (e.g. <code>venus.jar</code> becomes <code>RMvenus.jar</code>)
    and every JNLP client implementation has the right to mangle your names
    in a different way and you, therefore, can't predict the name with
    which your jar will be rechristend and end up on the user's machine in
    the application cache.Seems complex or impossible, to perform a simple task like opening a file.
    Please advise (I'm new to Java and Web Start).
    BTW, I'm working with IntelliJ IDEA 5.0.
    Thanks,
    Zedik.
    {font:Tahoma}{size:26pt}
    {size}{font}

    the follwing method i have used to open html file ...
    so to access html file i am shipping resources folder with jar file ..
    private void openHtmlPages(String pageName) {
         String cmd[] = new String[2];
         String browser = null;
         File file = null;
         if(System.getProperty("os.name").indexOf("Linux")>-1) {
              file = new File("/usr/bin/mozilla");
              if(!file.exists() ) {
              }else     {
                   browser = "mozilla";
         }else {
              browser = "<path of iexplore>";
         cmd[0] = browser;
         File files = new File("");
         String metaData = "/resources/Help/Files/"+pageName+".html"; // folder inside jar file
         java.net.URL url = this.getClass().getResource(metaData);
         String fileName = url.getFile();
         fileName = fileName.replaceAll("file:/","");
         fileName = fileName.replaceAll("%2520"," ");
         fileName = fileName.replaceAll("%20"," ");
         fileName = fileName.replaceAll("jarfilename.jar!"," ").trim();
         cmd[1] = fileName;     
         try{
              Process p = Runtime.getRuntime().exec(cmd);
         }catch(java.io.IOException io){
                   //Ignore
    can anyone give me the solution..???
    Regards
    Ganesan S

  • Opening a  File in Java

    The name of Ms-Exel file is stored in Ms-Access Database.
    Ms-Access Database . Report.dat
    There two Columns
    Rep_Name = which will have the Report Name
    Rep_Excel = Which will have Excel File name
    i will be creating a GUI whereby I will access the database and display the report names.
    Depending on what the user selects I woukd l like to make a call to Excel and Open that respected file for that Rep_Name.
    The File I am opening in Excel will be taken from the MS-ACCESS DATABASE.
    After the report is displayed , on clicking the close button there should be option to come back to the java program

    1. retieve th efilename from th edatabase.
    2. open the excel file
    for #2, if you want tyo open it within your Java application (so your Java application have access to the file..like to modify and update the Excel file)..then you will ned some sort of Excel API, like Jakarta POI as suggested. If you just want to open the excel file using MS Excel application (your Java application will not be able to do anything - like modify the Open Excel file) , then you can use Runtime class and its exec() method to launch the Excel application.

  • Opening  a file in vi Editor from Java

    My swing application is running on Linux platform. I need to open some .properties file from the GUI for editing.
    I tried to open the file abc.properties using the following methods
    1.
    String cmd = "vi abc.properties";
    Runtime.getRuntime().exec(cmd);
    2.
    String[] cmd = {"/bin/sh", "-c", "vi", "abc.properties"};
    Runtime.getRuntime().exec(cmd);
    3.
    String[] cmd = {"vi", "abc.properties"};
    Runtime.getRuntime().exec(cmd);
    All of them are running without any Exception, but not opening the vi editor with file..
    Any idea?

    If that is the case, then I think it is better
    - read the file contents to some editor swing
    component
    - edit the file
    - save the contents back to fileYes, I think that's by far the better solution. The only reason to call vi would probably be if
    - your program was targeted at a very small target audience
    - all of them are vivid vi-lovers
    - your application only needs to run on UNIX-like OSes with vi installed
    - the property file needs some complicated editing that the users prefer to do in vi
    Unless all of the above are true, I'd also suggest you just pop a text field with the content.

  • Java.util.zip.ZipException error in opening zip file

    Hello all,
    We are using Sun Java System web server 6.1 SP2. When I tried to deploy an application, I received this message: "Posted content length of --- exceeds limit of --- " the -dashes are the size of the file actually.
    I then added an init-param to the web.xml specifying the maximum size.
    After doing that, I tried to deploy the war file using administration interface, but received a network tcp/ip error. I then deployed it using command line wdeploy command. It worked but the web server won't start up after the deployment. The following error messages are found in the log file. Any thoughts as to whats wrong here? Is there a bug in SP2?
    [22/Sep/2006:17:30:44] finer ( 5668): ContextConfig[search]: URI='/search', ResourcePath='/WEB-INF/sun-web-search.tld' [22/Sep/2006:17:30:44] finer ( 5668): ContextConfig[search]:
    tldConfigJar(/WEB-INF/sun-web-search.tld): java.util.zip.ZipException: error in opening zip file
    [22/Sep/2006:17:30:44] finer ( 5668): ContextConfig[search]: URI='/jstl-fmt', ResourcePath='/WEB-INF/fmt.tld' [22/Sep/2006:17:30:44] finer ( 5668): ContextConfig[search]: tldConfigJar(/WEB-INF/fmt.tld): java.util.zip.ZipException: error in opening zip file
    [22/Sep/2006:17:30:48] failure ( 5668): CORE4007: Internal error: Unexpected Java exception thrown (java.lang.NoClassDefFoundError: org/xml/sax/ext/Attributes2, org/xml/sax/ext/Attributes2), stack: java.lang.NoClassDefFoundError: org/xml/sax/ext/Attributes2 at java.lang.ClassLoader.defineClass0(Native Method) at java.lang.ClassLoader.defineClass(ClassLoader.java:537) at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:123) at org.apache.catalina.loader.WebappClassLoader.findClassInternal(WebappClassLoader.java:1717) at org.apache.catalina.loader.WebappClassLoader.findClass(WebappClassLoader.java:983) at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1431) at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1301) at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:302) at org.apache.xerces.parsers.AbstractSAXParser.<init>(Unknown Source) at org.apache.xerces.parsers.SAXParser.<init>(Unknown Source) at org.apache.xerces.parsers.SAXParser.<init>(Unknown Source) at org.apache.xerces.jaxp.SAXParserImpl$JAXPSAXParser.<init>(Unknown Source) at org.apache.xerces.jaxp.SAXParserImpl.<init>(Unknown Source) at org.apache.xerces.jaxp.SAXParserFactoryImpl.newSAXParser(Unknown Source) at org.apache.catalina.util.xml.XmlMapper.readXml(XmlMapper.java:274) at org.apache.catalina.startup.ContextConfig.defaultConfig(ContextConfig.java:882) at org.apache.catalina.startup.ContextConfig.start(ContextConfig.java:1004) at org.apache.catalina.startup.ContextConfig.lifecycleEvent(ContextConfig.java:257) at org.apache.catalina.util.LifecycleSupport.fireLifecycleEvent(LifecycleSupport.java:155) at org.apache.catalina.core.StandardContext.start(StandardContext.java:3752) at com.iplanet.ias.web.WebModule.start(WebModule.java:257) at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1133) at org.apache.catalina.core.StandardHost.start(StandardHost.java:652) at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1133) at org.apache.catalina.core.StandardEngine.start(StandardEngine.java:355) at org.apache.catalina.startup.Embedded.start(Embedded.java:995) at com.iplanet.ias.web.WebContainer.start(WebContainer.java:431) at com.iplanet.ias.web.WebContainer.startInstance(WebContainer.java:500) at com.iplanet.ias.server.J2EERunner.confPostInit(J2EERunner.java:161) [22/Sep/2006:17:30:48] failure ( 5668): CORE3186: Failed to set configuration

    ooks like you are running into bug: 4719677
    When you deploy a web application using the Administration Server from a
    remote machine, the maximum upload size by default is 10 MB. This can be
    changed by editing the
    install-root/bin/https/webapps/instance-app/WEB-INF/web.xml file. In the
    servlet webappdeploy, insert an init param named maxUploadSize with a
    value in bytes specifying the maximum upload size. Example:
    <init-param>
    <param-name>maxUploadSize</param-name>
    <param-value>90000000</param-value>
    </init-param>

  • Java.util.zip.ZipException: error in opening zip file Deploment Error

    Hi All,
    I am getting the fallowing Deployment exception while i am trying to deploy my webdynpro DC. Kindly help me if anybody know the solution for it.
    deployment aborted : file:/C:/DOCUME1/291123/LOCALS1/Temp/temp7081pg.comiprscipr~dc_intreg_process.ear
    Aborted: development component 'ipr/scipr/dc_intreg_process'/'pg.com'/'GGD_EPREGDEV_D'/'20101220152524'/'0':Caught exception during application deployment from SAP J2EE Engine's deploy service:java.rmi.RemoteException: Error while getting the internal libraries of application pg.com/iprsciprdc_intreg_process in operation update.. Reason: error in opening zip file; nested exception is:      java.util.zip.ZipException: error in opening zip file (message ID: com.sap.sdm.serverext.servertype.i
    Thanks,
    Mahesh Nuli.

    Hello Ram,
    It is saying that the library file is missing. Can you deploy pg.com/iprsciprdc_intreg_process  first and try to deploy this ear temp7081pg.comiprscipr~dc_intreg_process.ear.
    Regards
    Nizamudeen SM

  • How can I open in java file a text file?

    Hi !
    For example I have a java file name Pencil.java and I have a text fie name Box.txt
    I want like that if ( a == b ) {open Box.txt}
    How can I do that ?
    Thanks.

    Yes I want to see what this text file contains. Like clicking to a text file with mouse and opens. Then I can see what it contains.
    I have a Java document Pencil.java and I have a text file Box.txt
    I will write a java code in pencil.java ( that I dont know ). Then when I enter a number from keyboard with
    Scanner write = new Scanner(System.in);
    int a = write.nextInt()
    if (a == b) {                } opens Box.txt
    For example
    I write to command prompt
    java pencil
    It wants from me a number : I will enter 3.
    It is same as b .
    Then Box.txt file opens.
    Edited by: zue on Jun 3, 2008 11:04 AM

  • How to open external files in a Java stored procedure?

    Hi y'all,
    I'm trying to open an external text file from a Java stored procedure. The java sp has been successfully loaded, resolved, published, etc. in Oracle. I'm using the following statement to try to open the file (enclosed in a try/catch block):
    BufferedReader fileObj = new BufferedReader(new FileReader("fileName.txt"));
    I'm getting a file not found error. Where is Oracle looking (i.e., what directory)?
    Your help is greatly appreciated,
    Gary

    <BLOCKQUOTE><font size="1" face="Verdana, Arial">quote:</font><HR>Originally posted by Gary Nool ([email protected]):
    Hi y'all,
    I'm trying to open an external text file from a Java stored procedure. The java sp has been successfully loaded, resolved, published, etc. in Oracle. I'm using the following statement to try to open the file (enclosed in a try/catch block):
    BufferedReader fileObj = new BufferedReader(new FileReader("fileName.txt"));
    I'm getting a file not found error. Where is Oracle looking (i.e., what directory)?
    Your help is greatly appreciated,
    Gary<HR></BLOCKQUOTE>
    Hi Gary,
    you must use a "database directory", e.g:
    SQL>create directory WORKING_DIR as '/home2/common/';
    SQL> select * from all_directories;
    OWNER DIRECTORY_NAME
    DIRECTORY_PATH
    SYS WORKING_DIR
    /home2/common/
    Gert

  • Open a file using java......... how?

    hi all
    I have a prob with my code
    the problem is by using the FileChooser like
    file = fileChooser.getSelectedFile();
    I have the file name but how can i open that file e.g. if file is word document then that file should open in word , if that file is HTML file then open in IE , and other files as well.
    is there any way to open a file
    plz help me
    Thanx
    Regards
    Satinderjit

    veer ji, try this code on your pc if you can. Click the print button and see that happens. thanx yuvraj:
    import java.awt.*;
    import java.awt.event.*;
    import java.awt.print.*;
    //import com.sun.java.swing.*;
    import javax.swing.*;
    public class ComponentPrinterFrame
    extends JFrame
    implements Printable {
    public static void main(String[] args) {
    ComponentPrinterFrame cpf = new ComponentPrinterFrame();
    cpf.setVisible(true);
    public ComponentPrinterFrame() {
    super("ComponentPrinterFrame v1.0");
    createUI();
    protected void createUI() {
    JPanel panel = new JPanel();
    JButton printButton = new JButton("Print");
    panel.add(printButton);
    panel.add(new JList(new Object[] { "One", "Two", "Three" }));
    panel.add(new JButton("Push me"));
    panel.add(new JCheckBox("Chess", true));
    panel.add(new JComboBox(new Object[] { "Eins", "Zwei", "Drei" }));
    printButton.addActionListener(new ActionListener() {
    public void actionPerformed(ActionEvent ae) {
    PrinterJob pj = PrinterJob.getPrinterJob();
    pj.setPrintable(ComponentPrinterFrame.this);
    if (pj.printDialog()) {
    try { pj.print(); }
    catch (PrinterException pe) {
    System.out.println(pe);
    setContentPane(panel);
    setSize(400, 400);
    // Center.
    Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
    Dimension frameSize = getSize();
    int x = (screenSize.width - frameSize.width) / 2;
    int y = (screenSize.height - frameSize.height) / 2;
    setLocation(x, y);
    addWindowListener(new WindowAdapter() {
    public void windowClosing(WindowEvent e) {
    dispose();
    System.exit(0);
    public int print(Graphics g, PageFormat pf, int pageIndex) {
    if (pageIndex != 0) return NO_SUCH_PAGE;
    Graphics2D g2 = (Graphics2D)g;
    g2.translate(pf.getImageableX(), pf.getImageableY());
    getContentPane().paint(g2);
    return PAGE_EXISTS;

Maybe you are looking for

  • How do i make a "fill in the blank" line????

    I am making a questionnaire and need to have lines/spaces that can be filled in. When i use the underscore it does not work bc it moves the lines and words. I need something that when i send the document to a client they can fill it out and e-mail it

  • Itunes not syncing all files to ipod - permissions error

    With the newest verison of itunes is not syncing all of my files to my ipod - this is so frustrating! I have taken itunes/quicktime completely off my dell and reloaded with the newest version of itunes/quicktime. Changed to manually managing my ipod

  • Best practice: managing FRA

    I was not sure this was the most appropriate forum for this question; if not, please feel free to make an alternative suggestion. For those of us who run multiple databases on a box with shared disk for FRA, I am finding the extra layer of ASM and db

  • Is there a version of Firefox that I can download to my Mac that has OS 10.4.11?

    I downloaded firefox 4 but it says it is not compatible with OS10.4.11. Is there a version that I can download that will work on My MacBook.

  • Can't reinstall Icloud 4.01

    I first tried to update 3.1 Icloud to 4.01 through the Apple Software Update program several times. It failed and said to do a manual only install through Tools. I did that several times. If fails with the message 'There is a problem with the Windows