JAVA Programming Help

BloodWolfJW

Marotheit
OP
Member
Joined
Feb 11, 2011
Messages
220
Trophies
0
Location
Colorado Springs
XP
222
Country
United States
So, I have a program I'm making in the process of taking my classes. I'll post my code below.

Code:
import java.util.Scanner;
public class ROMBox {

ÂÂÂÂpublic static void main(String[] args) {
ÂÂÂÂÂÂÂÂScanner ROM = new Scanner (System.in);
ÂÂÂÂÂÂÂÂfloat Region, Title, Hack, Emulator;
ÂÂÂÂÂÂÂÂ
ÂÂÂÂÂÂÂÂSystem.out.println ("Hello. Welcome to ROMBox. Please wait while we fetch the necessary files.");
ÂÂÂÂÂÂÂÂ
ÂÂÂÂÂÂÂÂtry {Thread.sleep(4000);} catch(InterruptedException e) {}
ÂÂÂÂÂÂÂÂ
ÂÂÂÂÂÂÂÂSystem.out.println ("");
ÂÂÂÂÂÂÂÂSystem.out.println ("Loading...");
ÂÂÂÂÂÂÂÂSystem.out.println ("");
ÂÂÂÂÂÂÂÂ
ÂÂÂÂÂÂÂÂtry {Thread.sleep(2000);} catch(InterruptedException e) {}
ÂÂÂÂÂÂÂÂ
ÂÂÂÂÂÂÂÂSystem.out.print ("Please Enter the Desired Region: ");
ÂÂÂÂÂÂÂÂRegion = ROM.nextFloat();
ÂÂÂÂÂÂÂÂ
ÂÂÂÂÂÂÂÂSystem.out.print ("Please Enter the Desired Title: ");
ÂÂÂÂÂÂÂÂTitle = ROM.nextFloat();
ÂÂÂÂÂÂÂÂ
ÂÂÂÂÂÂÂÂSystem.out.print ("Please Enter any Desired Hacks: ");
ÂÂÂÂÂÂÂÂHack = ROM.nextFloat();
ÂÂÂÂÂÂÂÂ
ÂÂÂÂÂÂÂÂSystem.out.print("Do You Have an Emulator Available? ");
ÂÂÂÂÂÂÂÂEmulator = ROM.nextFloat();

ÂÂÂÂ}

}

I don't need any programming tips or anything, I just need to know what the desired variable is. Right now, it says float, which will allow for numbers. What do I need to put to make it accept words? Thanks
laugh.gif
 

naglaro00

Mildly disturbed
Member
Joined
Jun 5, 2009
Messages
1,380
Trophies
0
Age
28
Location
Pulse
Website
Visit site
XP
171
Country
String variable = JOptionPane.showInputDialog ("Dialog here");

float anotherVariable = float.parseFloat (variable);

you input the words then it converts it into float

like that?
 

BloodWolfJW

Marotheit
OP
Member
Joined
Feb 11, 2011
Messages
220
Trophies
0
Location
Colorado Springs
XP
222
Country
United States
I need help again. I have the code for downloading a file from a URL, and I have JList and buttons; I need to know how to set up actionlisteners to download that file. It's easier if I just show you a picture.

I need the top 3 selections (United States, Licensed, and 3-D WorldRunner) to run the download code when I hit "Download".

2ms1ni8.png


Here's the code for the download:
Code:
import java.net.*;
import java.io.*;
public class Download
ÂÂÂÂ{
ÂÂÂÂÂÂpublic static void main(String[] args)
ÂÂÂÂÂÂ{
ÂÂÂÂÂÂÂÂ try
ÂÂÂÂÂÂÂÂ {
ÂÂÂÂÂÂ
ÂÂÂÂÂÂÂÂÂÂÂÂSystem.out.println("Connecting to ROM Host...\n");
ÂÂÂÂÂÂ
ÂÂÂÂÂÂÂÂÂÂÂÂURL url = new URL("http://www.fileden.com/files/2010/12/14/3038162/ROMBox/3-D WorldRunner.zip");
ÂÂÂÂÂÂÂÂÂÂÂÂurl.openConnection();
ÂÂÂÂÂÂÂÂÂÂÂÂInputStream reader = url.openStream();
ÂÂÂÂÂÂ
ÂÂÂÂÂÂÂÂÂÂÂÂFileOutputStream writer = new FileOutputStream("C:/3-D WorldRunner.zip");
ÂÂÂÂÂÂÂÂÂÂÂÂbyte[] buffer = new byte[153600];
ÂÂÂÂÂÂÂÂÂÂÂÂint bytesRead = 0;
ÂÂÂÂÂÂ
ÂÂÂÂÂÂÂÂÂÂÂÂSystem.out.println("Downloading...\n");
ÂÂÂÂÂÂ
ÂÂÂÂÂÂÂÂÂÂÂÂwhile ((bytesRead = reader.read(buffer)) > 0)
ÂÂÂÂÂÂÂÂÂÂÂÂ{ 
ÂÂÂÂÂÂÂÂÂÂÂÂÂÂ writer.write(buffer, 0, bytesRead);
ÂÂÂÂÂÂÂÂÂÂÂÂÂÂ buffer = new byte[153600];
ÂÂÂÂÂÂÂÂÂÂÂÂ}
ÂÂÂÂÂÂ
ÂÂÂÂÂÂ
ÂÂÂÂÂÂÂÂÂÂÂÂSystem.out.println("Done! Please Enjoy the ROM!");
ÂÂÂÂÂÂÂÂÂÂÂÂwriter.close();
ÂÂÂÂÂÂÂÂÂÂÂÂreader.close();
ÂÂÂÂÂÂÂÂ }
ÂÂÂÂÂÂÂÂ catch (MalformedURLException e)
ÂÂÂÂÂÂÂÂ {
ÂÂÂÂÂÂÂÂÂÂÂÂe.printStackTrace();
ÂÂÂÂÂÂÂÂ }
ÂÂÂÂÂÂÂÂ catch (IOException e)
ÂÂÂÂÂÂÂÂ {
ÂÂÂÂÂÂÂÂÂÂÂÂe.printStackTrace();
ÂÂÂÂÂÂÂÂ }
ÂÂÂÂÂÂ
ÂÂÂÂÂÂ}
ÂÂÂÂÂÂ
ÂÂÂÂ}
Here's the code for the program:
CODEimport java.awt.*;
import java.awt.Event.*;
import java.awt.FlowLayout;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
import java.net.*;
import java.io.*;
import javax.swing.*;
import javax.swing.event.*;
import javax.swing.plaf.PanelUI;
import javax.swing.JFrame;
import javax.swing.JButton;
import javax.swing.JList;
import javax.swing.JOptionPane;
import javax.swing.JLabel;
import javax.swing.JRootPane;
import javax.swing.JTextField;
import javax.swing.JPasswordField;

public class ROMBox extends JFrame{
ÂÂÂÂ
ÂÂÂÂpublic static void main(String[] args) {}
ÂÂÂÂ
ÂÂÂÂprivate JLabel Item1;
ÂÂÂÂprivate JLabel Item2;
ÂÂÂÂprivate Component add;
ÂÂÂÂ
ÂÂÂÂpublic ROMBox(){
ÂÂÂÂÂÂÂÂsuper("ROMBox: The Ultimate ROM Downloader");
ÂÂÂÂÂÂÂÂsetLayout(new FlowLayout());
ÂÂÂÂÂÂÂÂ
ÂÂÂÂÂÂÂÂJButton download;
ÂÂÂÂÂÂÂÂJButton information;
ÂÂÂÂÂÂÂÂ
ÂÂÂÂÂÂÂÂItem1 = new JLabel("Welcome to ROMBox. Please Set the Desired Preferences Below, and Begin Your Download.");
ÂÂÂÂÂÂÂÂadd(Item1);
ÂÂÂÂÂÂÂÂ
ÂÂÂÂÂÂÂÂadd (Box.createRigidArea(new Dimension(9999, 0)));
ÂÂÂÂÂÂÂÂadd (Box.createRigidArea(new Dimension(9999, 0)));
ÂÂÂÂÂÂÂÂ
ÂÂÂÂÂÂÂÂJList Region = null;
ÂÂÂÂÂÂÂÂString[] regions = {"United StatesÂÂ", "JapanÂÂ", "EuropeÂÂ", "OtherÂÂ"};
ÂÂÂÂÂÂÂÂRegion = new JList(regions);
ÂÂÂÂÂÂÂÂRegion.setVisibleRowCount(3);
ÂÂÂÂÂÂÂÂRegion.setSelectionMode (ListSelectionModel.SINGLE_SELECTION);
ÂÂÂÂÂÂÂÂadd(new JScrollPane (Region));ÂÂÂÂ
ÂÂÂÂÂÂÂÂ
ÂÂÂÂÂÂÂÂJList Licensing = null;
ÂÂÂÂÂÂÂÂString[] license = {"LicensedÂÂ", "UnlicensedÂÂ", "HackedÂÂ", "OtherÂÂ"};
ÂÂÂÂÂÂÂÂLicensing = new JList(license);
ÂÂÂÂÂÂÂÂLicensing.setVisibleRowCount(3);
ÂÂÂÂÂÂÂÂLicensing.setSelectionMode (ListSelectionModel.SINGLE_SELECTION);
ÂÂÂÂÂÂÂÂadd(new JScrollPane (Licensing));ÂÂÂÂ
ÂÂÂÂÂÂÂÂ
ÂÂÂÂÂÂÂÂJList Title = null;
ÂÂÂÂÂÂÂÂString[] titles = {"3-D WorldRunnerÂÂ", "8 EyesÂÂ", "10-Yard FightÂÂ", "720°ÂÂ", "1942ÂÂ", "1943 - The Battle of MidwayÂÂ"};
ÂÂÂÂÂÂÂÂTitle = new JList(titles);
ÂÂÂÂÂÂÂÂTitle.setVisibleRowCount(3);
ÂÂÂÂÂÂÂÂTitle.setSelectionMode (ListSelectionModel.MULTIPLE_INTERVAL_SELECTION);
ÂÂÂÂÂÂÂÂadd(new JScrollPane (Title));ÂÂÂÂ
ÂÂÂÂÂÂÂÂ
ÂÂÂÂÂÂÂÂadd (Box.createRigidArea(new Dimension(9999, 0)));
ÂÂÂÂÂÂÂÂadd (Box.createRigidArea(new Dimension(9999, 0)));
ÂÂÂÂÂÂÂÂ
ÂÂÂÂÂÂÂÂItem1 = new JLabel("By clicking \"Download\", you agree that this is ROM is for trial purposes only. All Rights Reserved.");
ÂÂÂÂÂÂÂÂadd(Item1);
ÂÂÂÂÂÂÂÂ
ÂÂÂÂÂÂÂÂadd (Box.createRigidArea(new Dimension(9999, 0)));
ÂÂÂÂÂÂÂÂadd (Box.createRigidArea(new Dimension(9999, 0)));
ÂÂÂÂÂÂÂÂ
ÂÂÂÂÂÂÂÂdownload = new JButton ("Download");
ÂÂÂÂÂÂÂÂadd (download);
ÂÂÂÂÂÂÂÂ
ÂÂÂÂÂÂÂÂinformation = new JButton ("Information");
ÂÂÂÂÂÂÂÂadd (information);
ÂÂÂÂÂÂÂÂ
ÂÂÂÂÂÂÂÂHandlerClass ROM = new HandlerClass();
ÂÂÂÂÂÂÂÂRegion.addListSelectionListener(ROM);
ÂÂÂÂÂÂÂÂLicensing.addListSelectionListener(ROM);
ÂÂÂÂÂÂÂÂTitle.addListSelectionListener(ROM);
ÂÂÂÂÂÂÂÂ
ÂÂÂÂÂÂÂÂ
ÂÂÂÂÂÂÂÂROM = new HandlerClass();
ÂÂÂÂÂÂÂÂdownload.addActionListener(ROM);
ÂÂÂÂÂÂÂÂinformation.addActionListener(ROM);
ÂÂÂÂÂÂÂÂ
ÂÂÂÂ}
ÂÂÂÂ
ÂÂÂÂprivate void addALine(String string, JRootPane rootPane) {
ÂÂÂÂÂÂÂÂ// TODO Auto-generated method stub
ÂÂÂÂÂÂÂÂ
ÂÂÂÂ}

ÂÂÂÂprivate class HandlerClass implements ActionListener, ListSelectionListener {

ÂÂÂÂÂÂÂÂpublic void actionPerformed(ActionEvent event) {
ÂÂÂÂÂÂÂÂÂÂÂÂJOptionPane.showMessageDialog(null, String.format("%s", event.getActionCommand()));
ÂÂÂÂÂÂÂÂ}

ÂÂÂÂÂÂÂÂ@Override
ÂÂÂÂÂÂÂÂpublic void valueChanged(ListSelectionEvent arg0) {
ÂÂÂÂÂÂÂÂÂÂÂÂ
ÂÂÂÂÂÂÂÂ}}

}
 

Site & Scene News

Popular threads in this forum

General chit-chat
Help Users
    B @ btjunior: i love sigma meals, skibidi slicers!!