New Posts  All Forums:Forum Nav:

Finishing a Program

post #1 of 5
Thread Starter 
Hey guys so im very curious as to how to make programs like a kilometer to mile converter. I have the code made already but in order to run the program i have to hit ctrl1 then ctrl2 in textpad in order to compile and run my program.

import javax.swing.*;
import java.awt.event.*;
import java.awt.*;

public class KiloConverter{
public static void main(String[] args){

KiloConverterWindow kc = new KiloConverterWindow();

}
}

class KiloConverterWindow extends JFrame{

private JPanel panel;
private JLabel messageLable;
private JTextField kiloTextField;
private JButton calcButton;
private final int width = 300;
private final int height = 300;

public KiloConverterWindow(){
setTitle("Kilo Converter");

setSize(width, height);

setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

buildPanel();

add(panel);

setVisible(true);
}

private void buildPanel(){
messageLable = new JLabel("Enter a distance in kilometers");

kiloTextField = new JTextField(10);

calcButton = new JButton("Calculate");

calcButton.addActionListener(new CalcButtonListener());

panel = new JPanel();

panel.add(messageLable);
panel.add(kiloTextField);
panel.add(calcButton);
}//end build panel

private class CalcButtonListener implements ActionListener{
public void actionPerformed(ActionEvent e){

String input;
double miles;
input = kiloTextField.getText();

miles = Double.parseDouble(input) * .6214;

JOptionPane.showMessageDialog(null, input + " kilometers is " + miles + " miles.");
}
}
}


this is my code and i want to make it into an app. can anyone introduce me to literature or websites or personal knowledge as to how this is done. If you want please take this code and and mod it so that it will do that im purely interested in learning and this is such an easily reproduced program that there is no chance of sales or w/e
Thanks for the help!
My Rig
(13 items)
 
  
CPUMotherboardGraphicsRAM
i7 860 Asus P7P55D PRO GTX 480 sli wc Corsair Vengeance  
Hard DriveOSPowerCase
WD 1TB BLACK x2 Windows 7 64 bit Silverstone Strider 1000+ CM 690 2 Advanced 
  hide details  
Reply
My Rig
(13 items)
 
  
CPUMotherboardGraphicsRAM
i7 860 Asus P7P55D PRO GTX 480 sli wc Corsair Vengeance  
Hard DriveOSPowerCase
WD 1TB BLACK x2 Windows 7 64 bit Silverstone Strider 1000+ CM 690 2 Advanced 
  hide details  
Reply
post #2 of 5
start > run > notepad

Code:
public class HelloWorld  {
    public static void main(String[] args)  {
        System.out.println("Hello!");
    }
}
save as C:\\HelloWorld.java

assume sun jdk is installed to C:\\jdk, and an environment variable JAVA_HOME is set to C:\\jdk . Add ;%JAVA_HOME%\\bin to your path environment variable so you can invoke java & javac directly.


start > run > cmd

> C:
> cd C:\\
> javac HelloWorld.java
> java Hello
Hello!

So there you have it. A running program. You just need to add that main() method bit to your file. google "java main method". And your main method will need to do { new KiloConverterWindow(); } and set default close operation etc.

In 10+ years of java coding, I have never once bundled into a windows exe or a unix binary.... in fact that is technically not possible without stuffing the whole jvm into there.

After you can run the .class file using the java command, you should bundle Hello.class into Hello.jar and add META-INF\\MANIFEST.MF which specifies main-class: Hello .. (google java manifest main-class). Then you can associate .jar files with the java command to run on double click from windows.

Next, you could have anyone launch it by going to a url if you deploy it with java web start, .jnlp . This is actually easier than you think and I kind of like it.

Next you'd convert it to a browser based application using a servlet framework.

native iphone/ipad app etc, i really don't care. I'll be getting into that over the next few months.. unfortunately
stable again
(25 items)
 
  
CPUCPUMotherboardGraphics
E5-2687W E5-2687W ASUS Z9PED8-WS EVGA GTX 570 (Linux host) 
GraphicsRAMHard DriveHard Drive
EVGA GTX 970 FTW (win7 guest) 64GB G.SKILL 2133 2x Crucial M4 256GB raid1 4x 3TB raid 10 
CoolingCoolingCoolingCooling
2x Apogee HD  2x RX 480 2x MCP 655 RP-452x2 rev2 (new) 
CoolingCoolingOSOS
16x Cougar Turbine CFT12SB4 (new) EK FC 580 Gentoo (host) Gentoo (x23 guests) 
OSMonitorMonitorPower
windows 7 (guest w/ vfio-pci) Viewsonic 23" 1080P Viewsonic 19" Antec HCP Platinum 1000 (new) 
CaseOtherOther
Case Labs TH10 (still the best ever) 2x Lamptron FC-5 IOGEAR 2 way DVI KVM Switch 
  hide details  
Reply
stable again
(25 items)
 
  
CPUCPUMotherboardGraphics
E5-2687W E5-2687W ASUS Z9PED8-WS EVGA GTX 570 (Linux host) 
GraphicsRAMHard DriveHard Drive
EVGA GTX 970 FTW (win7 guest) 64GB G.SKILL 2133 2x Crucial M4 256GB raid1 4x 3TB raid 10 
CoolingCoolingCoolingCooling
2x Apogee HD  2x RX 480 2x MCP 655 RP-452x2 rev2 (new) 
CoolingCoolingOSOS
16x Cougar Turbine CFT12SB4 (new) EK FC 580 Gentoo (host) Gentoo (x23 guests) 
OSMonitorMonitorPower
windows 7 (guest w/ vfio-pci) Viewsonic 23" 1080P Viewsonic 19" Antec HCP Platinum 1000 (new) 
CaseOtherOther
Case Labs TH10 (still the best ever) 2x Lamptron FC-5 IOGEAR 2 way DVI KVM Switch 
  hide details  
Reply
post #3 of 5
Thread Starter 
thanks so very much. There are a few things i dont understand yet but i plan on doing a lot of research into this so that i can fully understand it.
My Rig
(13 items)
 
  
CPUMotherboardGraphicsRAM
i7 860 Asus P7P55D PRO GTX 480 sli wc Corsair Vengeance  
Hard DriveOSPowerCase
WD 1TB BLACK x2 Windows 7 64 bit Silverstone Strider 1000+ CM 690 2 Advanced 
  hide details  
Reply
My Rig
(13 items)
 
  
CPUMotherboardGraphicsRAM
i7 860 Asus P7P55D PRO GTX 480 sli wc Corsair Vengeance  
Hard DriveOSPowerCase
WD 1TB BLACK x2 Windows 7 64 bit Silverstone Strider 1000+ CM 690 2 Advanced 
  hide details  
Reply
post #4 of 5
Thread Starter 
so im having trouble with cmd prompt compiling. In my windows install folders i have jdk1.6.0_21 which has the javac application in it but every time i hit javac HelloWorld.java i get the error javac not recognized as an internal or external command my paths and environment is as follows.

User Variables
CLASSPATH ;C:\\Program Files\\Java\\jdk1.6.0_21\\bin\\javac.exe

System variables
Path C:\\Program Files\\Java\\jdk1.6.0_21\\bin\\javac.exe
QTJAVA C:\\Program Files\\Java\\jre6\\lib\\ext\\QTJava.zip
Edited by Sin Cities Sin - 2/23/11 at 7:37pm
My Rig
(13 items)
 
  
CPUMotherboardGraphicsRAM
i7 860 Asus P7P55D PRO GTX 480 sli wc Corsair Vengeance  
Hard DriveOSPowerCase
WD 1TB BLACK x2 Windows 7 64 bit Silverstone Strider 1000+ CM 690 2 Advanced 
  hide details  
Reply
My Rig
(13 items)
 
  
CPUMotherboardGraphicsRAM
i7 860 Asus P7P55D PRO GTX 480 sli wc Corsair Vengeance  
Hard DriveOSPowerCase
WD 1TB BLACK x2 Windows 7 64 bit Silverstone Strider 1000+ CM 690 2 Advanced 
  hide details  
Reply
post #5 of 5
Thread Starter 
i got the command prompt to work here on my laptop but not on my desk top oddly enough but it is ok as this is where i do all my programming anyways. Thank you for your help i will follow the rest of your post now to try and make different apps
My Rig
(13 items)
 
  
CPUMotherboardGraphicsRAM
i7 860 Asus P7P55D PRO GTX 480 sli wc Corsair Vengeance  
Hard DriveOSPowerCase
WD 1TB BLACK x2 Windows 7 64 bit Silverstone Strider 1000+ CM 690 2 Advanced 
  hide details  
Reply
My Rig
(13 items)
 
  
CPUMotherboardGraphicsRAM
i7 860 Asus P7P55D PRO GTX 480 sli wc Corsair Vengeance  
Hard DriveOSPowerCase
WD 1TB BLACK x2 Windows 7 64 bit Silverstone Strider 1000+ CM 690 2 Advanced 
  hide details  
Reply
New Posts  All Forums:Forum Nav:
  Return Home
  Back to Forum: Coding and Programming