Convert to windowed application-JFrame

I need to convert this program into a windowed application of the subclass JFrame and use Graphics method drawString to output the totals. I know I need to import java awt.* and java. awt.event.* but other than that I need help. Thanks.
// Roll a six-sided die 6000 times
import javax.swing.*;
public class RollDie {
   public static void main( String args[] )
      int face, frequency[] = new int[ 7 ];
      String output = "";
      for ( int roll = 1; roll <= 6000; roll++ ) {
         face = 1 + ( int ) ( Math.random() * 6 );
         ++frequency[ face ];
      output += "Face\tFrequency"
      for ( face = 1; face < frequency.length; face++ )
         output += "\n" + face + "\t" + frequency[ face ];
      JTextArea outputArea = new JTextArea( 7, 10 );
      outputArea.setText( output );
      JOptionPane.showMessageDialog( null, outputArea,
         "Rolling a Die 6000 Times",
         JOptionPane.INFORMATION_MESSAGE );
      System.exit( 0 );
}

import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
public class RollDie extends JFrame {
     JFrame frame;
     public RollDie(){
          frame = new JFrame();
          frame.setVisible(true);
          frame.setSize(400,400);
          frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
          Container contentpane = frame.getContentPane();
          int face, frequency[] = new int[ 7 ]; 
          String output = "";     
          for ( int roll = 1; roll <= 6000; roll++ ) {
               face = 1 + ( int ) ( Math.random() * 6 );       
             ++frequency[ face ];   
             output += "Face\tFrequency";     
             for ( face = 1; face < frequency.length; face++ )
             output += "\n" + face + "\t" + frequency[ face ];   
             JTextArea outputArea = new JTextArea( 7, 10 );   
             outputArea.setText( output );    
             contentpane.add(outputArea);
             JOptionPane.showMessageDialog( null, outputArea,         "Rolling a Die 6000 Times",         JOptionPane.INFORMATION_MESSAGE );   
             System.exit( 0 ); 
            public static void main( String args[] )   { 
            RollDie rd = new RollDie();
}

Similar Messages

  • Is correct? Application (JFrame) to Applet (JApplet)

    I need to convert a java application (JFrame) into an applet (JApplet), and I have seen a few "big steps":
    1�: make the class extends to JApplet instead of a JFrame
    2�: To replace the construction method by init ()
    3�: To comment the main method
    Is correct?, because I have some doubts that later I�ll explain
    Thanks

    I think in the init method (in a JApplet) I cannot call the super method. but my problem is how to change this? if in others files (in Files.java) I have calls to super metod, because thus it constructs a dialog box, asking for a file.
    In file Files.java I have a class called "Abort" (extends to JDialog) in whitch:
    /* class Files.java */
    class Abort extends JDialog
              boolean abort = true;
              JTextArea mensage = null;
              JButton acept = new JButton("Acept");
              JButton cancel = new JButton("Cancel");
              Abort(String nanemFile)
                   super(MainClassFile.mainWindow, " Attention!", true);
    /* clas Files.java */Please help

  • Windows application inside jFrame

    Is there away of displaying windows application such as word or excel document inside java application. For display purpose only. If so please share your code.
    Thanks

    there might be code that allows activeX objects to be embeded in Java apps, in which case, if the Windows app exposes itself as an ActiveX object, then it should work.

  • Windows Application Starting Point

    Does a basic (and best practice) framework (or netbeans like project) exist for a java windows application that would include menuing and initial windows classes?
    I have decided to create a application in java and it will be a windows gui application. I understand how to do this but it seems like this would be something someone else has already done. Kind of a starting point for an application. Does something like this exists? I searched online but didn't find anything. Maybe this is because I'm not sure what I'm asking for.

    I haven't seen any nice GUI frameworks for Java, beyond what Java already gives you. It would depend somewhat on what the app does. And you have to decide if you want to use Swing or SWT. Based on a previous thread, it would seem there are also some GUI builder tools out there, if you don't want to hand code it, but they won't produce very nice code; they just help prevent you from having to write it yourself. If this is your first jump into Java GUI, here is a quick Hello World app I just threw together in using Swing; it's a starting point anyway, and might help you get going:
    import java.awt.FlowLayout;
    import java.awt.event.ActionEvent;
    import java.awt.event.ActionListener;
    import java.awt.event.WindowEvent;
    import javax.swing.BorderFactory;
    import javax.swing.JFrame;
    import javax.swing.JLabel;
    import javax.swing.JMenu;
    import javax.swing.JMenuBar;
    import javax.swing.JMenuItem;
    import javax.swing.JPanel;
    import javax.swing.SwingUtilities;
    public class HelloWorld {
         public static void main(String[] args) {
              // Code that affects the GUI should be run on the Event Dispatch thread;
              // Calling launchUI() using SwingUtilities.invokeLater(...) takes care of this.
              SwingUtilities.invokeLater(new Runnable() {
                   public void run() {
                        launchUI();
         private static void launchUI() {
              final JFrame frame = new JFrame("Hello World");
              JPanel panel = new JPanel(new FlowLayout());
              JLabel label = new JLabel("Hello World!");
              panel.add(label);
              panel.setBorder(BorderFactory.createEmptyBorder(20, 20, 20, 20));
              JMenuBar menuBar = new JMenuBar();
              JMenu menu = new JMenu("File");
              JMenuItem menuItem = new JMenuItem("Exit");
              menuItem.addActionListener(new ActionListener() {
                   public void actionPerformed(ActionEvent event) {
                        // This action will be fired when the Exit menu item is selected;
                        // firing off a Window Closing event is basically the same thing
                        // pressing the window close button in the corner does.
                        WindowEvent windowClosingEvent = new WindowEvent(frame, WindowEvent.WINDOW_CLOSING);
                        frame.getToolkit().getSystemEventQueue().postEvent(windowClosingEvent);
              menu.add(menuItem);
              menuBar.add(menu);
              frame.setJMenuBar(menuBar);
              frame.setContentPane(panel);
              frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
              frame.pack();
              frame.setLocationRelativeTo(null);     // this centers the frame
              frame.setVisible(true);
    }

  • Embedding Applet in native Windows Application

    Hi!
    I need to integrate applet into my windows application (MSVC).
    The problem is displaying applet(s) within the application's main window (just like in browser).
    Is there a way to do it? Using WebBrowser (IE) ActiveX component is unacceptable.
    Perhaps there is documentation how to use JRE browser plugin, but googling yielded no results :(

    <offtopic>Apparently my login no longer working, re-registered</offtopic>
    ActiveX bridge won't do, I have to load an applet from any .jar
    The idea is to write kind of applet loader, which may be able to load jar and display applet.
    To start with, I need to know the way of paiting Java application GUI (i.e. JFrame) inside the native window.
    There is one way I've found. First, create borderless JFrame with some unique title, then use FindWindow in C++ Application to obtain HWND (window handle), and then call SetParent. I know there is more elegant way using JAWT to obtain HWND, the main problem is that Java window is rendered separately and only then becomes a part of native window, because HWND could be get on visible window only. This results unneccessary mess and flicking on screen for user.
    So, how can I render Java GUI directly to native window?
    I used search and haven't found solution.
    Thank you!
    PS found http://forum.java.sun.com/thread.jspa?forumID=52&threadID=5124062
    but this guy haven't said how he ded that :(
    Edited by: deniska25 on Oct 15, 2007 1:52 PM

  • Drag and drop in windowed application

    i have created application using drag and drop funcatinalities .it's working in webbrowser as internet application .but i converted int o a windowed application and dra and drop isn't working in that form as desktop app.
    pls help me
    thank you.

    Maybe I should mention that this drag and drop feature doesn't work on ALL the programs, which leads me to believe that this is a system preferences problem. I can't drag into any of the Adobe programs, iPhoto, Kodak Easyshare, etc.
    I understand the Get Info solution, but that is pinpointing only one type of file... I would like to fix this feature for all files.
    Thanking in advance, Ck

  • LSMW with CI on System i and an additional Windows Application Server 4.70

    Hi together,
    I have a really tricky problem to realize a parallel processing LSMW Workload.
    In truth it isn't a problem to the parallel processing. It is a problem, how to declare the paths to the input files.
    The LSMW is splittet in four steps:
    1. Read data
    2. Convert Data
    3. Creating Batch Input File (IDOCS)
    4. Start Direct Input Program
    The first three points are using file in the IFS.
    In the 13 points of LSMW there is point " 7 Specify Files" where I can customize paths to the real existing input and output-Files, which are stored at the IFS on System i.
    For example:
    Legacy Data          On the R/3 server (application server)                           
        Materialtexte                  /usr/sap/direct/lsmw/material/matsta_text.txt      
    This works fine.
    Now we have added a Windows Applications Server in front of the 2-Tier enviroment to have more performance to the BTC workprocesses. Now we have two servers shown in sm51. One is the central instance (CI) and the other is the application server (AS), which is working together with the CI.
    <b>Now the big bug:</b> In the LSMW transaction, you can submit the job to batch (BTC) and can't choose the server (Instance) where the batchjob should run. So, sometimes the batchjob runs on the CI (iSeries) and sometimes the batchjob runs on the application server.
    But this is the problem, because the files in the IFS are only stored at IFS on iSeries. And if the Job runs at the application-server, the files is not found, and the job end abnormal.
    Now I tried to find a good solution. So I want to declare a patch in LSMW, that the batchjob is running successful at CI and AS.
    So I tried:
    \iSeriesshareusrsapdirectlsmwmaterialmatsta_text.txt
    But this is not really working, because the SAP WP can't find this file with this path.
    There is a second possibility: Not to submit the batchjobs by pressing F9 in the transaction LSMW but making an extra job in sm36 for each job. Not very smart !
    There is a third possibility: To duplicate the import Files to each Windows Application Server. Then it is possible to submit by pressing F9,  whatever server will be used.
    So my question is:  What is the right way? There must be some poeple in the world who have done a migration with iSeries an Windows Application Server together? Or not?
    best regards,
    Carsten
    Message was edited by: C.Schulz
    path corrected:
    iSeries\share\usr\sap\direct\lsmw\material\matsta_text.t
            Carsten Schulz

    >
    \iSeriesshareusrsap/direct/lsmw/material/matsta_text.txt
    Windows doesn't understand forward slashes, you need to use backslashes all way:
    Try the following on one of the application servers:
    Start - execute
    notepad \iSeriesshareusrsapdirectlsmwmaterialmatsta_text.txt
    If you can open the file, that's the way to go.
    You'd need to check in your program, whether the job is been executed on Windows or non-windows and substitute the slashes accordingly.
    Markus

  • Some minor issues we are facing in converting the 6i application to 10g ,

    Regarding 10g froms i need support in resolving following issues:-
    1. Direct print to default printer
    In some of our applications user do not want to see the print preview and prefer direct print in 6i we were doing this by defining Desitination in report paramenters
    2. Open each form in new window
    We open each new form using OPEN_FORM() builtin, but all forms open in same MDI window, how using open form we can open the forms in new window
    3. Maintaining source code in windows and linux
    Initaially our developers test the forms under windows 10g AS environment but when the same form in uploaded on Linux machine they need to make some changes like " replacing all \ with /, converting all paths to lower case etc
    how we can write the same code for linux and windows
    These are some minor issues we are facing in converting the 6i application to 10g environment ...

    1) We don't do direct printing. We print everything to PDF files in a user's network mapped drive. They print or preview as required.
    2) We overcame this problem by using Java WebStart
    [http://groundside.com/blog/JanCarlin.php?title=forms_and_java_web_start&more=1&c=1&tb=1&pb=1]
    It frees Forms from being browser based and looks more like a 'real' application.
    3) We use FormsAPI Master [Link to ORCL-Toolbox|http://www.orcl-toolbox.com/] to automatically convert from Windows to Unix. Our script converts uppercase to lowercase for icons, menus, library attachments, etc. We only do this once - unless new libraries have been attached in the wrong case. For things like '\' to '/' , Windows is quite happy to accept '/' as a delimiter. "cd C:\temp" is the same as "cd c:/temp". However, there are obvious differences between Windows and Unix. If there is any interaction between the Form and the operating system, then we do all our testing in the Unix environment - leaving Windows as a "does the screen layout look OK" environment.

  • Creating Windows Application Installer from Flash

    Hey,
    hope someone can help me out
    Im trying to find out with there is a possibility to convert or make a flash .exe file into a Windows Application and have it installed on the the computer.
    I mean when you click the file it starts to instal on the computer like an application, creates shortcuts and so on. im guessing it has soming to do with AIR but cant seem to get it.
    Any help will be much appriciated. Thanks in advance!
    pavel

    Ya i googled it and came up with many results, I was
    just wondering if anyone thought one was better than
    othersAh.
    Well, it would have been good if you'd stated that in the first place. That might have engendered some discussion.
    Better still would be if you tried out two or three of them, formed your own opinion, then posted that here and asked if other had similar experiences, or if there were any major issues that you might have missed in your testing, etc.

  • How to Execute Power Shell Command From Windows Application.

    Hi All Experts,
    I want to execute power shell commands from my windows application.
    Is it possible ?
    Please let me know your comments..
    Thanks.

    I have not tried this, but apprently it is easy as in the sample pasted below. please see this article for more details
    http://geekswithblogs.net/Norgean/archive/2012/09/19/running-powershell-from-within-sharepoint.aspx.
    Let me know how it goes...
    public string RunPowershell(string powershellText, SPWeb web, string param1, string param2) {
    // Powershell ~= RunspaceFactory - i.e. Create a powershell context
    var runspace = RunspaceFactory.CreateRunspace();
    var resultString = new StringBuilder();
    try
    // load the SharePoint snapin - Note: you cannot do this in the script itself (i.e. add-pssnapin etc does not work)
    PSSnapInException snapInError;
    runspace.RunspaceConfiguration.AddPSSnapIn("Microsoft.SharePoint.PowerShell", out snapInError);
    runspace.Open();
    // set a web variable.
    runspace.SessionStateProxy.SetVariable("webContext", web);
    // and some user defined parameters
    runspace.SessionStateProxy.SetVariable("param1", param1);
    runspace.SessionStateProxy.SetVariable("param2", param2);
    var pipeline = runspace.CreatePipeline();
    pipeline.Commands.AddScript(powershellText);
    // add a "return" variable
    pipeline.Commands.Add("Out-String");
    // execute!
    var results = pipeline.Invoke();
    // convert the script result into a single string
    foreach (PSObject obj in results)
    resultString.AppendLine(obj.ToString());
    finally
    // close the runspace
    runspace.Close();
    // consider logging the result. Or something.
    return resultString.ToString();
    Ok. We've written some code. Let us test it.
    var runner = new PowershellRunner();
    runner.RunPowershellScript(@"
    $web = Get-SPWeb 'http://server/web' # or $webContext
    $web.Title = $param1
    $web.Update()
    $web.Dispose()
    ", null, "New title", "not used");
    -Sangeetha

  • JSP and windows application

    I have a windows application (convert.exe sitting on my C: drive) that I want to call it and place it on my JSP page in specific co-ordinates. How can I do this? Please help. Thanks in advance.

    If you rely upon the system default encoding at some point of your applciation when you convert a byte stream to a character stream, then the behaviour of the application will depend on the platform default encoding, which can be different on those boxes.

  • Problem on using Crystal Report Viewer on windows application ("specified type is not valid ")

    Hi
    I am having problem on using Crystal Report Viewer on one of my windows application.
    I am not sure how to put the Crystal Report Viewer 11 Control onto the tool box.
    I could found a Crystal Report Viewer control on my computer, but it is version 8.5.
    I have also found another one which is Called Crytal ActiveX Report Viewer, i don't think it is the one I can use. As when I try to load a dummy report on to the Crytal ActiveX Report Viewer, It return an error. "specified type is not valid"
    Please see the Code sample below.
    private sub loadReport()
         Dim r as New ReportDocument
         'v is the name of the Crystal ActiveX Report Viewer Control
         r.Load("C:\Report1.rtp")
         v.ReportSource(r) <---It throw error on this line.
    End Sub
    Could you give me some advice about what have I done wrong, How to check if I have set up the Crystal Report Component correctly in my Visual Studio 2005 Standard edition.
    Thanks in advances.
    Many thanks
    Chi

    VS 2005 Standard and Express editions do not come with Crystal Reports; only the Professional and higher editions will have CR bundled. However, I believe you can purchase CR XI R2 Developer and it will give you the components you need to create a VS .NET 2005 application using the Standard edition.
    -MJ

  • How do I convert my Windows 7 Folder to an ISO image to burn to a USB, in order to use Bootcamp Assistant to partition my MacBook Pro for Mac and Windows?

    How do I convert my Windows 7 Folder to an ISO image to burn to my  USB Flash drive (16GB)  in order to use Bootcamp Assistant to partition my MacBook Pro for Mac and Windows?

    Sorry - confusing - My question has NOT been solved yet - can anyone help?

  • Can Bootcamp and Parallels share the same Windows applications and data?

    I'm looking at getting an Intel iMac which will let me throw away my old PC - Yeah!
    I will have a couple of Win apps that I will need to hang on to (Quicken - Quicken for Mac is horrible, but that's another tghread). Anyway, can Bootcamp and Parallels share the same Windows applications and data?
    My thought would be to allow my wife to access Quicken from Parallels and not have to reboot. She will only need lightweight access and the overhead of running virtualization wouldn't impact her. I, on the other hand, would want to occasionally boot natively into Windows and run the same application with the same datafile. Is this possible?
    Thanks and looking forward to joining the MacIntel world!

    Thanks for all of the freplies. I suspected that BootCamp and Parallels could not shar ethe same partition, but wanted to verify. To address some of the other posts:
    Re: Quicken vs MoneyDance - I looked at MoneyDance a while back and while it is comparable to Quicken for Mac, it isn't comparable to Quicken for Windows (ergo, Quicken for Mac isn't comparable to Quicken for Windows!). But, as I said, that is a topic for another thread!
    Re: Using Bootcamp/Parallels for only one app: I actually have several apps that I still need access to on Windows. I work with many business applications than only run/are supported on Windows as well as receive some complex Office documents which Office for Mac cannot handle. Quicken (for Windows 2007) was just the best example of a consumer app where I could see wanting access from both OS X and Windows.

  • How can i convert a window media player file into a format playable on ipod

    hey guys can you tell me how can i convert an widdow media player file into a format that can be played on my ipod, i used videora ipod converter but it can't convert the window media player file

    the program you show change wma to mp3, but the mp3 file can't be understanded by the iPod, how can i change a wma file to a format understanded by the Ipod?

Maybe you are looking for