Doesnt allow keyboard input in Numbers
i used numbers all day every day.
Today all of a sudden, whenever i select a field to imput data, every keystroke enters nothing and just makes the BUMB BUMB BUMB noise, like its not an allowed action. This also applies to the save menu in trying to name the file.
This is only happeneing in numbers, no other program. I have also tried looking a several other spreadsheets, all with the same problem.
They are not locked......
any ideas?
Have you rebooted?
Can you open any of the files in another user space?
Similar Messages
-
Keyboard input from numbers 1-0 not recognized
On my ibook G4 which I recently started using again, I've noticed that now all input from the "number bar", that is, digits one through zero, is not recognized, that is, it's as if I weren't pressing it at all. I've gone through system preferences, reset everything to default, and I've even done three separate PMU resets, but to no avail. Curiously, all the F keys function. I have access to some number input with the "number lock" feature, but any number that resides on the actual number bar like seven eight or nine cannot be entered. I have no problem with ~, -, +, or delete, either. Any help to point me in the right direction would be greatly appreciated.
Hey Danger and Welcome to Apple Discussions,
It sounds like the horizontal trace that links the numbers together has developed an open. I know of no way to repair this and the solution would be a replacement keyboard. Verify the problem isn't software related by plugging in a USB keyboard and checking function.
Richard -
Define speakable command dialog box does not allow keyboard input
According to article http://support.apple.com/kb/PH11447, one is supposed to easily be able to create speakable commands based on keyboard shortcuts:
Open the app that contains the shortcut you want.
Press the listening key (or speak the key, depending on your settings), and then speak the command “Define a keyboard command.”
In the “Define keyboard command” window, use the keyboard shortcut (such as Command-S), and then click OK.
Type the phrase you want to use to name the command, such as “Save document.”
Step 4 doesn't work, because the dialog box won't permit any input or even allopw the cursor to be in the field.
Any ideas on how to fix/work around this?Apple doesn't routinely monitor the discussions.
Send Apple feedback. They won't answer, but at least will know there is a problem. If enough people send feedback, it may get the problem solved sooner.
Feedback -
Applet opens a form doesn't allow keyboard input
Hi,
I testing something so everything I've done is really simple. I wrote a JApplet that has a JMenubar. Selecting a menu item opens a new webpage which contains an HTML form. The form has 2 radio buttons and a text field. The problem is I can't type anything into the text field. Press keys just causes the computer to go "ding" at me.
If I open a new browser for the form the text field is accessible. I want to keep the form in the same window. What's wrong with my code?
<applet>
import java.applet.Applet;
import java.awt.Graphics;
import javax.swing.*;
import javax.swing.JApplet.*;
import java.awt.event.*;
import java.net.*;
public class MenuApplet extends JApplet
StringBuffer buffer;
public void init()
buffer = new StringBuffer();
/* addItem("init..."); */
try
javax.swing.SwingUtilities.invokeAndWait(new Runnable()
{public void run()
{createMenu();}
catch (Exception e)
{ System.err.println("createMenu didn't successfully complete"); }
void createMenu()
JMenuBar jmb = new JMenuBar();
setJMenuBar(jmb);
JMenu menu = new JMenu("Listings");
jmb.add(menu);
JMenuItem contactList = new JMenuItem("Contacts");
menu.add(contactList);
JMenuItem customerList = new JMenuItem("Customers");
menu.add(customerList);
contactList.addActionListener(new ActionListener()
{ public void actionPerformed(ActionEvent ae)
{ boolean good;
good = linkTo("file:///c:/1.private/pages/testform.html");
void addItem(String newWord)
System.out.println(newWord);
buffer.append(newWord);
repaint();
private boolean linkTo(String theURLString)
try
URL theURL = new URL(theURLString);
getAppletContext().showDocument(theURL);
catch(MalformedURLException e)
System.out.println("Bad URL: " + theURLString + "\n");
return false;
return true;
</applet>
<html>
<HTML>
<HEAD>
<TITLE></TITLE>
<meta http-equiv="Content-Type" content="text/html; charset=us-ascii">
<meta name="generator" content="CSE HTML Validator Professional (http://www.htmlvalidator.com/)">
</HEAD>
<BODY>
<APPLET CODE="MenuApplet.class" WIDTH="100%" HEIGHT="25px"></APPLET>
</BODY>
</HTML>
</html>
<html form>
<HTML>
<HEAD>
<TITLE>Testing forms</TITLE>
</HEAD>
<BODY ONLOAD="document.tf.criteria.focus()">
<!-- <FORM METHOD="POST" ACTION="tracker/jte/contactslist.p"> -->
<FORM NAME="tf" METHOD="POST" ACTION="file:///c:/1.private/pages/tables.html">
<FIELDSET>
<P>Search by:<BR>
<INPUT TYPE="RADIO" NAME="searchtype" VALUE="customer" CHECKED>Customer <BR>
<INPUT TYPE="RADIO" NAME="searchtype" VALUE="contact">Contact <BR>
</P>
<P>
Enter name:
<INPUT TYPE="TEXT" NAME="criteria" VALUE="who">
</P>
<INPUT TYPE="SUBMIT">
</FIELDSET>
</FORM>
</BODY>
</HTML>
</html form>P.S. This problem occurs when using Netscape 6.2. The applet works fine with IE 6.0.26. Other than "use ie" does anyone have any suggestions?
-
I am unable to set up an iTunes billing account as I don't have an issue number on my card, I have tried just inputting different numbers such as just putting 1 but its not allowing me further!?
Sorry, but you can't. You can only use a credit card issued by a French bank and with a French billing address. Your only solution is going to be to purchase prepaid iTunes cards (there should be several places you can buy them; perhaps FNAC) and use prepaid cards to open the account and purchase.
Regards. -
Keyboard input allowed with iPhone/iTouch remote software?
I have searched through the posts but haven't seen a definite answer: Can anyone confirm if keyboard input via the iPhone/iTouch remote software is available with the ATV 2.1 update? I don't have an iPod Touch (yet) so I can't test this out.
Utilizing an iPod Touch/iPhone virtual keyboard would be SO much better than the little white remote when doing searches in Youtube/iTunes music etc.Works like a champ using 2.0 and Remote on my Gen 1 iPhone.
You can type in search terms and it behaves just like iTunes, narrowing the results as you type.
Plus you can scroll long lists of songs or other content very rapidly and use the alphabet column (like Contacts on the phone) to jump quickly.
-dan -
http://www.rafb.net/paste/results/D3082433.html
In that link are all three of my classes (UserInterface.java, CalcEngine.java, and Calculator.java)
I'm trying to do keyboard input for the numbers, the decimal, all the operations and enter. But the way I have it set up, I can't get any of the methods in the CalcEngine.java to run once a button is pressed. It's hard for me the explain, but if you compile it and try looking at the code, you'll understand what I mean.
-sachitAlright, I'll post the 3 classes here.
#### UserInterface.java ####
// Date Started: March 1, 2004
// Date Finished: March 26, 2004
// Program Description: A graphical user interface for the calculator.
// No calculation is being done here. This class is
// responsible just for putting up the display on
// screen. It then refers to the "CalcEngine" to do
// all the real work.
import java.awt.*;
import java.awt.event.*;
public class UserInterface implements KeyListener
private CalcEngine calc;
Frame panelFrame=new Frame("Non-Scientific Calculator");
static Label displayLabel;
static String button="";
// Method Name: UserInterface()
// Parameters Passed: None
// Data Returned: None
// Method Purpose: A user interface for the given calcEngine.
public UserInterface()
makeFrame();
panelFrame.setVisible(true);
// Method Name: setVisible()
// Parameters Passed: boolean variable visible
// Data Returned: None
// Method Purpose: Sets the panalFrame interface visible.
public void setVisible(boolean visible)
panelFrame.setVisible(visible);
// Method Name: makeFrame()
// Parameters Passed: None
// Data Returned: None
// Method Purpose: The full display of buttons and labels on the calculator.
private void makeFrame()
CalcEngine buttonHandler = new CalcEngine();
Button[] myButtons=new Button[30];
String[] labels={"","","BS","CE","C","PI","sin","cos","tan","%","sqrt","7","8","9","/","x�","4","5","6","x","1/x","1","2","3","-","-/+","0",".","=","+"};
Font titleFont=new Font("Courier", Font.BOLD,20);
Font buttonFont=new Font("Arial", Font.BOLD,13);
String display="0";
displayLabel=new Label(display);
String info = buttonHandler.getInfo();
Label infoLabel=new Label(info);
//Labels all the buttons
for(int i=0;i<myButtons.length;i++)
myButtons=new Button(labels[i]);
panelFrame.setLayout(new BorderLayout(4,5));
panelFrame.setBackground(Color.gray);
displayLabel.setFont(titleFont);
displayLabel.setAlignment(Label.RIGHT);
panelFrame.add("North",displayLabel);
Panel secondPanel=new Panel();
panelFrame.add("Center",secondPanel);
secondPanel.setLayout(new GridLayout(6,5,5,2));
secondPanel.setBackground(Color.gray);
for(int i=0; i<myButtons.length; i++)
secondPanel.add(myButtons[i]);
myButtons[i].setFont(buttonFont);
myButtons[i].addKeyListener(this);
myButtons[i].addActionListener(buttonHandler);
myButtons[0].setBackground(Color.gray);
myButtons[0].hide();
myButtons[1].hide();
panelFrame.add("South",infoLabel);
panelFrame.resize(270,250);
panelFrame.show();
// Method Name: redisplay()
// Parameters Passed: None
// Data Returned: None
// Method Purpose: Updates the display of the current number being inputed.
// Also truncates the decimal if it is ".0".
public static void redisplay()
boolean itsInt=false;
int doubleChecker = (int)CalcEngine.getDisplayValue();
int intValue=0;
if(CalcEngine.getDisplayValue() == (float)doubleChecker)
intValue=(int)Math.round(CalcEngine.getDisplayValue());
itsInt=true;
if(itsInt)
displayLabel.setAlignment(Label.RIGHT);
displayLabel.setText("" +intValue);
else
displayLabel.setAlignment(Label.RIGHT);
displayLabel.setText("" + CalcEngine.getDisplayValue());
public void keyTyped(KeyEvent e)
char keyChar = e.getKeyChar();
button=""+keyChar;
CalcEngine calcEng= new CalcEngine();
if(keyChar == '+')
System.out.println("+ PRESSED!");
else if(keyChar == '-')
System.out.println("- PRESSED!");
else if(keyChar == KeyEvent.VK_SLASH)
System.out.println("/ PRESSED!");
else if(keyChar == '*')
System.out.println("x PRESSED!");
else if(keyChar == KeyEvent.VK_1)
System.out.println("1 PRESSED!");
else if(keyChar == KeyEvent.VK_2)
System.out.println("2 PRESSED!");
else if(keyChar == KeyEvent.VK_3)
System.out.println("3 PRESSED!");
else if(keyChar == KeyEvent.VK_4)
System.out.println("4 PRESSED!");
else if(keyChar == KeyEvent.VK_5)
System.out.println("5 PRESSED!");
else if(keyChar == KeyEvent.VK_6)
System.out.println("6 PRESSED!");
else if(keyChar == KeyEvent.VK_7)
System.out.println("7 PRESSED!");
else if(keyChar == KeyEvent.VK_8)
System.out.println("8 PRESSED!");
else if(keyChar == KeyEvent.VK_9)
System.out.println("9 PRESSED!");
else if(keyChar == KeyEvent.VK_0)
System.out.println("0 PRESSED!");
else if(keyChar == KeyEvent.VK_ENTER || keyChar == KeyEvent.VK_EQUALS)
calcEng.equals();
System.out.println("= PRESSED!");
else if(keyChar == KeyEvent.VK_PERIOD)
System.out.println(". PRESSED!");
/*else
/// QUESTION: what do these next two lines do?
byte bytes[] = {(byte)keyChar};
System.out.println(bytes);
// command = new String(bytes);
public static String passButton()
return button;
public void keyPressed(KeyEvent e)
public void keyReleased(KeyEvent e)
#### CalcEngine.java #####
// Date Started: March 1, 2004
// Date Finished: March 26, 2004
// Program Description: Does all the calculations for the calculator.
import java.awt.event.*;
import java.awt.*;
public class CalcEngine implements ActionListener
final int ARRAY_SIZE=100;
String []buttonPressed = new String[ARRAY_SIZE];
String buttonCheck="";
static String userDisplay="";
int numberLength=0;
int currentNumber=0;
int previousNumber=0;
int currentElement=0;
boolean allowDecimal=true;
boolean cEPressed=false;
String buttonCheckKey;
// Method Name: CalcEngine()
// Parameters Passed: None
// Data Returned: None
// Method Purpose: Instance of the CalcEngine.
public CalcEngine()
buttonCheckKey=UserInterface.passButton();
buttonCheck=buttonCheckKey;
System.out.println("ButtonCheckKey " +buttonCheck);
if(buttonCheck=="=")
if(currentElement>=2 && !buttonPressed[currentElement].equals(""))
equals();
else if(buttonCheck.equals("C"))
clear();
else if(buttonCheck.equals("CE"))
clearOne();
else if(buttonCheck.equals("BS"))
backSpace();
else if(buttonCheck.equals("sqrt"))
squareRoot();
else if(buttonCheck.equals("sin") || buttonCheck.equals("cos") || buttonCheck.equals("tan"))
trig(buttonCheck);
else if(buttonCheck.equals("PI"))
numPI();
else if(buttonCheck.equals("1/x"))
oneOver();
else if(buttonCheck.equals("x�"))
powerTwo();
else if(buttonCheck.equals("-/+"))
negPos();
//else if(buttonCheck.equals("."))
// decimal(event);
else if((buttonCheck.equals("+") || buttonCheck.equals("-") || buttonCheck.equals("x") || buttonCheck.equals("/") || buttonCheck.equals("%")) && !buttonPressed[currentElement].equals(""))
operations(buttonCheck);
//else
// allNumbers(event);
System.out.println("1st: "+buttonPressed[0]+ "\n2nd: " buttonPressed[1] "\n3rd: " buttonPressed[2] "\n4th: " buttonPressed[3] "\n5th: " +buttonPressed[4]);
System.out.println("6th: "+buttonPressed[5]+ "\n7th: " buttonPressed[6] "\n8th: " buttonPressed[7] "\n9th: " buttonPressed[8]"\n");
// Method Name: getDisplayValue()
// Parameters Passed: None
// Data Returned: float variable N/A
// Method Purpose: Retrived the updated number to display on the calculator
// and passes it as a double.
public static double getDisplayValue()
return Double.valueOf(userDisplay).doubleValue();
// Method Name: actionPerformed()
// Parameters Passed: ActionEvent variable event
// Data Returned: None
// Method Purpose: Run the correct method depending on what button is pressed.
public void actionPerformed(ActionEvent event/*, String button, boolean keyBoard*/)
//Removes null from buttonPressed array
for(int i=0; i<buttonPressed.length; i++)
if(buttonPressed[i]==null)
buttonPressed[i]="";
numberLength++;
buttonCheck=event.getActionCommand(); //Gets the button that was pressed
//Runs the correct method depending on which button is pressed
if(buttonCheck=="=")
if(currentElement>=2 && !buttonPressed[currentElement].equals(""))
equals();
else if(buttonCheck.equals("C"))
clear();
else if(buttonCheck.equals("CE"))
clearOne();
else if(buttonCheck.equals("BS"))
backSpace();
else if(buttonCheck.equals("sqrt"))
squareRoot();
else if(buttonCheck.equals("sin") || buttonCheck.equals("cos") || buttonCheck.equals("tan"))
trig(buttonCheck);
else if(buttonCheck.equals("PI"))
numPI();
else if(buttonCheck.equals("1/x"))
oneOver();
else if(buttonCheck.equals("x�"))
powerTwo();
else if(buttonCheck.equals("-/+"))
negPos();
else if(buttonCheck.equals("."))
decimal(event);
else if((buttonCheck.equals("+") || buttonCheck.equals("-") || buttonCheck.equals("x") || buttonCheck.equals("/") || buttonCheck.equals("%")) && !buttonPressed[currentElement].equals(""))
operations(buttonCheck);
else
allNumbers(event);
System.out.println("1st: "+buttonPressed[0]+ "\n2nd: " buttonPressed[1] "\n3rd: " buttonPressed[2] "\n4th: " buttonPressed[3] "\n5th: " +buttonPressed[4]);
System.out.println("6th: "+buttonPressed[5]+ "\n7th: " buttonPressed[6] "\n8th: " buttonPressed[7] "\n9th: " buttonPressed[8]"\n");
// Method Name: clear()
// Parameters Passed: None
// Data Returned: None
// Method Purpose: Is run if the "C" button is pressed. Clears all the numbers
// inputted into the calculator.
public void clear()
for(int i=0; i<buttonPressed.length; i++)
buttonPressed[i]="";
userDisplay="0";
currentElement=0;
numberLength=0;
UserInterface.redisplay();
// Method Name: clearOne()
// Parameters Passed: None
// Data Returned: None
// Method Purpose: Is run if the "CE" button is pressed. Deletes the last
// entire number inputted into the calculator. For example,
// if "5x123" was inputted, it would go back to "5x".
public void clearOne()
if(currentElement >= 2)
buttonPressed[currentElement]="";
userDisplay=buttonPressed[currentElement-2];
numberLength=0;
cEPressed=true;
UserInterface.redisplay();
// Method Name: backSpace()
// Parameters Passed: None
// Data Returned: None
// Method Purpose: Is run if the "BS" button is pressed. Deletes the last
// number inputted into the calculator. For example,
// if "5x123" was inputted, it would go back to "5x12".
public void backSpace()
int stringSize=buttonPressed[currentElement].length();
buttonPressed[currentElement] = userDisplay.substring(0, userDisplay.length() - 1);
userDisplay=buttonPressed[currentElement];
UserInterface.redisplay();
// Method Name: trig()
// Parameters Passed: String variable buttonCheck
// Data Returned: None
// Method Purpose: Is run if the "sin", "cos", or "tan" button is pressed.
// Finds the sin, cos or tan of the current number.
public void trig(String buttonCheck)
if(buttonCheck.equals("sin"))
double sinThisNum=Double.valueOf(buttonPressed[currentElement]).doubleValue();
double sinNum=Math.sin(sinThisNum);
buttonPressed[currentElement]=""+sinNum;
else if(buttonCheck.equals("cos"))
double cosThisNum=Double.valueOf(buttonPressed[currentElement]).doubleValue();
double cosNum=Math.cos(cosThisNum);
buttonPressed[currentElement]=""+cosNum;
else if(buttonCheck.equals("tan"))
double tanThisNum=Double.valueOf(buttonPressed[currentElement]).doubleValue();
double tanNum=Math.tan(tanThisNum);
buttonPressed[currentElement]=""+tanNum;
userDisplay=buttonPressed[currentElement];
UserInterface.redisplay();
// Method Name: squareRoot()
// Parameters Passed: None
// Data Returned: None
// Method Purpose: Is run if the "sqrt" button is pressed. Sqaures the current
// number.
public void squareRoot()
if(currentElement==0 || currentElement % 2==0)
double rootThisNum=Double.valueOf(buttonPressed[currentElement]).doubleValue();
double rootedNum=Math.sqrt(rootThisNum);
buttonPressed[currentElement]=""+rootedNum;
userDisplay=buttonPressed[currentElement];
UserInterface.redisplay();
// Method Name: numPI()
// Parameters Passed: None
// Data Returned: None
// Method Purpose: Is run if the "PI" button is pressed. Allows the user to
// input the value of PI.
public void numPI()
double PInumber=Math.PI;
buttonPressed[currentElement]=""+PInumber;
userDisplay=buttonPressed[currentElement];
UserInterface.redisplay();
// Method Name: oneOver()
// Parameters Passed: None
// Data Returned: None
// Method Purpose: Is run if the "1/x" button is pressed. This will divide
// the current number by 1.
public void oneOver()
if(currentElement==0 || currentElement % 2==0)
double oneOverNum=Double.valueOf(buttonPressed[currentElement]).doubleValue();
oneOverNum=1/oneOverNum;
buttonPressed[currentElement]=""+oneOverNum;
userDisplay=buttonPressed[currentElement];
UserInterface.redisplay();
// Method Name: powerTwo()
// Parameters Passed: None
// Data Returned: None
// Method Purpose: Is run if the "x^2" button is pressed. This will take the
// current number to the power 2.
public void powerTwo()
if(currentElement==0 || currentElement % 2==0)
double powNum=Double.valueOf(buttonPressed[currentElement]).doubleValue();
powNum=Math.pow(powNum,2);
buttonPressed[currentElement]=""+powNum;
userDisplay=buttonPressed[currentElement];
UserInterface.redisplay();
// Method Name: negPos()
// Parameters Passed: None
// Data Returned: None
// Method Purpose: Is run if the "-/+" button is pressed. Toggles the number
// between a negative and positive value.
public void negPos()
if(userDisplay.charAt(0)!='-')
userDisplay="-"+userDisplay;
else
userDisplay=userDisplay.substring(1);
buttonPressed[currentElement]=userDisplay;
UserInterface.redisplay();
// Method Name: decimal()
// Parameters Passed: ActionEvent variable event
// Data Returned: None
// Method Purpose: Is run if the "C" button is pressed. Clears all the numbers
// inputted into the calculator.
public void decimal(ActionEvent event)
if(allowDecimal)
buttonPressed[currentElement]+=event.getActionCommand();
userDisplay+=event.getActionCommand();
allowDecimal=false;
UserInterface.redisplay();
// Method Name: operations()
// Parameters Passed: String variable buttonCheck
// Data Returned: None
// Method Purpose: Is run if the "+","-","x","/","%" button is pressed. Depending
// on which operation is selected, the calculator will perform that.
public void operations(String buttonCheck)
currentElement++;
if(buttonCheck.equals("+"))
buttonPressed[currentElement]="+";
else if(buttonCheck.equals("-"))
buttonPressed[currentElement]="-";
else if(buttonCheck.equals("x"))
buttonPressed[currentElement]="x";
else if(buttonCheck.equals("/"))
buttonPressed[currentElement]="/";
else if(buttonCheck.equals("%"))
buttonPressed[currentElement]="%";
currentElement++;
numberLength=0;
userDisplay="0";
allowDecimal=true;
// Method Name: allNumbers()
// Parameters Passed: ActionEvent variable event
// Data Returned: None
// Method Purpose: Is run if any of the numbers are pressed. Adds the inputted
// number to the already ongoing number in the display.
public void allNumbers(ActionEvent event)
if(checkInt(event.getActionCommand()))
if(cEPressed)
buttonPressed[currentElement]+=event.getActionCommand();
UserInterface.redisplay();
userDisplay=event.getActionCommand();
cEPressed=false;
UserInterface.redisplay();
else
buttonPressed[currentElement]+=event.getActionCommand();
userDisplay+=event.getActionCommand();
UserInterface.redisplay();
// Method Name: checkInt()
// Parameters Passed: String variable dataInput
// Data Returned: None
// Method Purpose: A quick check to see if the button pressed is a number.
// Rather than doing if(buttonCheck=="1") for every number.
public boolean checkInt(String dataInput)
try
int n=Integer.parseInt(dataInput);
return true;
catch (NumberFormatException nfe)
return false;
// Method Name: equals()
// Parameters Passed: None
// Data Returned: None
// Method Purpose: Is run if the "=" button is pressed. Takes all the inputted
// numbers and operations and executes all the calculations.
public void equals()
double firstNum=0;
double secondNum=0;
double currentAns=0;
int howBig=0;
for(int i=0; i<buttonPressed.length;i+=2)
if(buttonPressed[i]!="")
howBig++;
firstNum=Double.valueOf(buttonPressed[0]).doubleValue();
for(int j=0; j<=howBig-1; j+=2)
secondNum=Double.valueOf(buttonPressed[j+2]).doubleValue();
if(buttonPressed[j+1].equals("+"))
currentAns=firstNum+secondNum;
else if(buttonPressed[j+1].equals("-"))
currentAns=firstNum-secondNum;
else if(buttonPressed[j+1].equals("x"))
currentAns=firstNum*secondNum;
else if(buttonPressed[j+1].equals("/"))
currentAns=firstNum/secondNum;
else if(buttonPressed[j+1].equals("%"))
currentAns=firstNum%secondNum;
firstNum=currentAns;
for(int i=0; i<buttonPressed.length; i++)
buttonPressed[i]="";
buttonPressed[0]=""+currentAns;
currentElement=0;
userDisplay=""+currentAns;
UserInterface.redisplay();
// Method Name: getInfo()
// Parameters Passed: None
// Data Returned: String variable N/A
// Method Purpose: Return the title of this calculation engine.
public String getInfo()
return "ver 0.9 Copyright � 2001-2003 Harish.";
### Calculator.java ###
// Date Started: March 1, 2004
// Date Finished: March 26, 2004
// Program Description: The main class of a simple calculator.
public class Calculator
private CalcEngine engine;
private UserInterface gui;
// Method Name: Calculator()
// Parameters Passed: None
// Data Returned: None
// Method Purpose: Creates the calculator and displays it on the screen.
public Calculator()
engine = new CalcEngine();
gui = new UserInterface();
// Method Name: show()
// Parameters Passed: None
// Data Returned: None
// Method Purpose: If the window is closed, it will show it again.
public void show()
gui.setVisible(true);
// Method Name: main()
// Parameters Passed: String variable []args
// Data Returned: None
// Method Purpose: The main method that runs the Calculator()
public static void main(String [] args)
new Calculator();
-s64 -
How do I input multiple numbers to go to multiple variables in one line?
I was wondering what I had to do to input 5 variables on one line. I have the program running fine, but I'm stuck at the part where it says "The numbers will be input five per line, on four lines".. Aside from poor grammar, it doesn't make any sense to me. Here's the whole question:
Write code that will fill the array twoDArray(declared in the line of code below) with numbers typed in at the keyboard. The numbers will be input five per line, on four lines. Use the following array declaration:I don't need any immediate help with the array itself, just the input (unless the input is directly related to the array). Just in case, I'm going to post my code. This is still very messy, because I'm not done, and it's might be somewhat sloppy as I'm new to 2d arrays (in java).
Thanks for the help.
import java.io.*;
class darrays
public static void main(String[] args) throws IOException
InputStreamReader inStream = new InputStreamReader (System.in);
BufferedReader stdin = new BufferedReader(inStream);
int[][] twoDArray = new int[4][5];
int x,y;
String input;
for (x = 0; x <= 3; x++)
for (y = 0; y<=4; y++)
input = stdin.readLine ();
twoDArray[x][y] = Integer.parseInt (input);
for (x = 0; x <= 3; x++)
for (y = 0; y<=4; y++)
System.out.print(twoDArray[x][y] + " ");
System.out.println("");
}Slightly off-topic
When I was learning Basic (good old Kemeny & Kurtz style, when Basic was simply a simplified Fortran, not Bill Gates style) you simply have to write
READ A, B, C, D, E
DATA 10, 20, 30, 40, 50
or something like
INPUT "A", A: INPUT "B", B etc.
In Java you are required to handle the mysteries of StringTokenizer...
Java 1.5 is promising to make it easier:
Scanner sc = Scanner.create(new File("myNumbers"));
while (sc.hasNextLong()) {
long aLong = sc.nextLong();
}where you get the longs (decimal formatted, separated with blanks) from a text file.
But not so easy as the good old INPUT statement.
Even C's scanf is not so easy, because has lots of subtleties
(when you finally mastered the esoteric art of using char* as strings, you are really fed up of char* strings, because they usually blow up due to buffer overflows or mere programmer errors, and start to use Java instead, even having to master the StringTokenizer and other classes.). -
Setting keyboard input to default to phone
Trying to figure out how to set my keyboard input to default to the phone, NOT to search or any other text-based input. I want to be able to type a phone number into my phone and call someone. Is this too much to ask? I have spent hours trying to figure this out and can't find an answer. Help please! And thanks.
I don't think so, that I know of.
Are most of your calls all dialed by number or are there a few numbers you dial quite often?
You can set a screen shortcut to those.
1. If any post helps you please click the below the post(s) that helped you.
2. Please resolve your thread by marking the post "Solution?" which solved it for you!
3. Install free BlackBerry Protect today for backups of contacts and data.
4. Guide to Unlocking your BlackBerry & Unlock Codes
Join our BBM Channels (Beta)
BlackBerry Support Forums Channel
PIN: C0001B7B4 Display/Scan Bar Code
Knowledge Base Updates
PIN: C0005A9AA Display/Scan Bar Code -
I need to get Keyboard input as well as mouse input on a JButton
I need to get Keyboard input as well as mouse input on a JButton
I have attempted to implement KeyListener. I get the keyCode but I need it to go in to the same String variable as my Actionlistener section.Here is the code I have trouble with getting keyboard input as wells as mouse input into the same variable.
public class Calctester extends JFrame
implements ActionListener, KeyListener
private double var1, var2;//var1 and var2 are used to perform calculation
String operand1 = "";//takes first input until an operator is pressed
String operand2 = "";//takes input after operator is invoked
double result;//is used to store the result
boolean flag = false;//to signal operator pressed
boolean decimalFlag = false;//to signal decimal pressed
String stringInput;//used as a temporary store for all entry to allow for conditions to be evaluated
char ch; //used to store the operator for comparison//Reason is pre does not compare using string
String pre = "";//used to store the operator
double mem; //will hold memory operation values
double vMod; //Temporary store for var2 to be used with percent operations
//Creates buttons
JButton btn0 = new JButton("0");
JButton btn1 = new JButton("1");
JButton btn2 = new JButton("2");
JButton btn3 = new JButton("3");
JButton btn4 = new JButton("4");
JButton btn5 = new JButton("5");
JButton btn6 = new JButton("6");
JButton btn7 = new JButton("7");
JButton btn8 = new JButton("8");
JButton btn9 = new JButton("9");
JButton btnC = new JButton("C");
JButton btnCE = new JButton("CE");
JButton btnBkpSpc = new JButton("Backspace");
JButton btnPlus = new JButton("+");
JButton btnMinus = new JButton("-");
JButton btnMultiply = new JButton("*");
JButton btnDivide = new JButton("/");
JButton btnEquals = new JButton("=");
JButton btnPeriod = new JButton(".");
JButton btnPlusMinus = new JButton("+/-");
JButton btnSqrt = new JButton("sqrt");
JButton btnMod = new JButton("%");
JButton btnOneOverX = new JButton("1/x");
JButton btnMC = new JButton("MC");
JButton btnMR = new JButton("MR");
JButton btnMS = new JButton("MS");
JButton btnMPlus = new JButton("M+");
//Displays Text area for Display
JTextField txtArea = new JTextField("0.");//The calculation display area set to 0.
JTextField mArea = new JTextField();//to display memory operations
//Default constructor
Calctester()
//Defines a content pane
Container c = getContentPane();
//Defines the layout of the frame and sets it to null to allow absolute positioning
c.setLayout(null);
//Defines event handling
btn0.addActionListener(this);
btn1.addActionListener(this);
btn2.addActionListener(this);
btn3.addActionListener(this);
btn4.addActionListener(this);
btn5.addActionListener(this);
btn6.addActionListener(this);
btn7.addActionListener(this);
btn8.addActionListener(this);
btn9.addActionListener(this);
btnC.addActionListener(this);
btnCE.addActionListener(this);
btnBkpSpc.addActionListener(this);
btnPlus.addActionListener(this);
btnMinus.addActionListener(this);
btnDivide.addActionListener(this);
btnMultiply.addActionListener(this);
btnEquals.addActionListener(this);
btnPeriod.addActionListener(this);
btnPlusMinus.addActionListener(this);
btnSqrt.addActionListener(this);
btnMod.addActionListener(this);
btnOneOverX.addActionListener(this);
btnMR.addActionListener(this);
btnMS.addActionListener(this);
btnMPlus.addActionListener(this);
btnMC.addActionListener(this);
btn1.addKeyListener(this);
//Adds the buttons to the frame and sets the font of the label to be
//logical font Dialog,plain as opposed to Bold and the label size to 12
//Also sets the border type of aech button
c.add(btn0).setFont(new Font("Dialog", Font.PLAIN, 12));
btn0.setBorder(new BevelBorder(BevelBorder.RAISED));
c.add(btn1).setFont(new Font("Dialog", Font.PLAIN, 12));
btn1.setBorder(new BevelBorder(BevelBorder.RAISED));
c.add(btn2).setFont(new Font("Dialog", Font.PLAIN, 12));
btn2.setBorder(new BevelBorder(BevelBorder.RAISED));
c.add(btn3).setFont(new Font("Dialog", Font.PLAIN, 12));
btn3.setBorder(new BevelBorder(BevelBorder.RAISED));
c.add(btn4).setFont(new Font("Dialog", Font.PLAIN, 12));
btn4.setBorder(new BevelBorder(BevelBorder.RAISED));
c.add(btn5).setFont(new Font("Dialog", Font.PLAIN, 12));
btn5.setBorder(new BevelBorder(BevelBorder.RAISED));
c.add(btn6).setFont(new Font("Dialog", Font.PLAIN, 12));
btn6.setBorder(new BevelBorder(BevelBorder.RAISED));
c.add(btn7).setFont(new Font("Dialog", Font.PLAIN, 12));
btn7.setBorder(new BevelBorder(BevelBorder.RAISED));
c.add(btn8).setFont(new Font("Dialog", Font.PLAIN, 12));
btn8.setBorder(new BevelBorder(BevelBorder.RAISED));
c.add(btn9).setFont(new Font("Dialog", Font.PLAIN, 12));
btn9.setBorder(new BevelBorder(BevelBorder.RAISED));
c.add(btnC).setFont(new Font("Dialog", Font.PLAIN, 12));
btnC.setBorder(new BevelBorder(BevelBorder.RAISED));
c.add(btnCE).setFont(new Font("Helvetica", Font.PLAIN, 12));
btnCE.setBorder(new BevelBorder(BevelBorder.RAISED));
c.add(btnBkpSpc).setFont(new Font("Dialog", Font.PLAIN, 12));
btnBkpSpc.setBorder(new BevelBorder(BevelBorder.RAISED));
c.add(btnPlus).setFont(new Font("Dialog", Font.PLAIN, 12));
btnPlus.setBorder(new BevelBorder(BevelBorder.RAISED));
c.add(btnMinus).setFont(new Font("Dialog", Font.PLAIN, 12));
btnMinus.setBorder(new BevelBorder(BevelBorder.RAISED));
c.add(btnMultiply).setFont(new Font("Dialog", Font.PLAIN, 12));
btnMultiply.setBorder(new BevelBorder(BevelBorder.RAISED));
c.add(btnDivide).setFont(new Font("Dialog", Font.PLAIN, 12));
btnDivide.setBorder(new BevelBorder(BevelBorder.RAISED));
c.add(btnEquals).setFont(new Font("Dialog", Font.PLAIN, 12));
btnEquals.setBorder(new BevelBorder(BevelBorder.RAISED));
c.add(btnPeriod).setFont(new Font("Dialog", Font.PLAIN, 12));
btnPeriod.setBorder(new BevelBorder(BevelBorder.RAISED));
c.add(btnPlusMinus).setFont(new Font("Dialog", Font.PLAIN, 12));
btnPlusMinus.setBorder(new BevelBorder(BevelBorder.RAISED));
c.add(btnMod).setFont(new Font("Albertus Medium", Font.PLAIN, 12));
btnMod.setBorder(new BevelBorder(BevelBorder.RAISED));
c.add(btnSqrt).setFont(new Font("Microsoft San Serif", Font.PLAIN, 11));
btnSqrt.setBorder(new BevelBorder(BevelBorder.RAISED));
c.add(btnOneOverX).setFont(new Font("Dialog", Font.PLAIN, 12));
btnOneOverX.setBorder(new BevelBorder(BevelBorder.RAISED));
c.add(btnMC).setFont(new Font("Dialog", Font.PLAIN, 12));
btnMC.setBorder(new BevelBorder(BevelBorder.RAISED));
c.add(btnMS).setFont(new Font("Dialog", Font.PLAIN, 12));
btnMS.setBorder(new BevelBorder(BevelBorder.RAISED));
c.add(btnMR).setFont(new Font("Dialog", Font.PLAIN, 12));
btnMR.setBorder(new BevelBorder(BevelBorder.RAISED));
c.add(btnMPlus).setFont(new Font("Dialog", Font.PLAIN, 12));
btnMPlus.setBorder(new BevelBorder(BevelBorder.RAISED));
//sets the color of the label of the buttons
btnC.setForeground(Color.red);
btnCE.setForeground(Color.red);
btnBkpSpc.setForeground(Color.red);
btnDivide.setForeground(Color.red);
btnMultiply.setForeground(Color.red);
btnMinus.setForeground(Color.red);
btnPlus.setForeground(Color.red);
btnMC.setForeground(Color.red);
btnMR.setForeground(Color.red);
btnMS.setForeground(Color.red);
btnMPlus.setForeground(Color.red);
btnEquals.setForeground(Color.red);
btn0.setForeground(Color.blue);
btn1.setForeground(Color.blue);
btn2.setForeground(Color.blue);
btn3.setForeground(Color.blue);
btn4.setForeground(Color.blue);
btn5.setForeground(Color.blue);
btn6.setForeground(Color.blue);
btn7.setForeground(Color.blue);
btn8.setForeground(Color.blue);
btn9.setForeground(Color.blue);
btnPlusMinus.setForeground(Color.blue);
btnSqrt.setForeground(Color.blue);
btnMod.setForeground(Color.blue);
btnOneOverX.setForeground(Color.blue);
btn0.setFocusPainted(false);
btnPlus.setFocusPainted(false);
btnEquals.setFocusPainted(false);
//The display text area and the memory operation text area
c.add(txtArea);
txtArea.setBorder(new BevelBorder(BevelBorder.LOWERED));
txtArea.setBounds(7,0,240,25);//To provide a Text box @ the top of the frame
txtArea.setEditable(false);
txtArea.setBackground(Color.white);
c.add(mArea);
mArea.setBounds(13, 35, 28, 25);
mArea.setEditable(false);
mArea.setBorder(new BevelBorder(BevelBorder.LOWERED));
setSize(260,251);//size of the frame
setTitle("Calculator"); //Title
setVisible(true); //this makes the frame visible on the screen
setResizable(false); //this disallow resizing of the frame
setDefaultCloseOperation(EXIT_ON_CLOSE);//to close app
//instead of the above method you can use the WindowsListener which extennds other classes and implements other interfaces.
setLocation(300,200);//positioning of the window on the screen
txtArea.setHorizontalAlignment(JTextField.RIGHT);//sets the text in the text field to the right
mArea.setHorizontalAlignment(JTextField.CENTER);//centers the label
JMenu editMenu = new JMenu("Edit");//creates menu
JMenuItem copy = new JMenuItem("Copy Ctrl+C");//creates menu item
copy.addActionListener(this);//event handling
JMenuItem paste = new JMenuItem("Paste Ctrl+V");//creates menu
paste.addActionListener(this);//event handling
JMenuBar myMenu = new JMenuBar();//declares a menu bar
setJMenuBar(myMenu);//adds the menu bar to the frame
editMenu.setBorderPainted(false);//removes the border shadow around the menu bar
myMenu.setBorderPainted(false);//removes the border shadow around menu bar
//adds menu items to the menu, sets the font and font size.
editMenu.add(paste).setFont(new Font("Dialog", Font.PLAIN, 12));//
editMenu.add(copy).setFont(new Font("Dialog", Font.PLAIN, 12));
myMenu.add(editMenu).setFont(new Font("Dialog", Font.PLAIN, 12));
JMenu viewMenu = new JMenu("View");//creates menu
JMenuItem sci = new JMenuItem("Scientific");//creates menu item
sci.addActionListener(this);//event handling
JMenuItem std = new JMenuItem("Standard");//creates menu item
//adds menu items to the menu, sets the font and font size.
viewMenu.add(sci).setFont(new Font("Dialog", Font.PLAIN, 12));
viewMenu.add(std).setFont(new Font("Dialog", Font.PLAIN, 12));
myMenu.add(viewMenu).setFont(new Font("Dialog", Font.PLAIN, 12));
JMenu helpMenu = new JMenu("Help");//creates menu
JMenuItem helpTopics = new JMenuItem("Help Topics");//creates menu item
JMenuItem aboutCalc = new JMenuItem("About Calculator");//creates menu item
helpTopics.addActionListener(this);//event handling
//helpTopics.setBorder(new BevelBorder(BevelBorder.RAISED));
helpTopics.setBorder(LineBorder.createGrayLineBorder());
//adds menu items to the menu, sets the font and font size.
helpMenu.add(helpTopics).setFont(new Font("Dialog", Font.PLAIN, 12));
helpMenu.add(aboutCalc).setFont(new Font("Dialog", Font.PLAIN, 12));
myMenu.add(helpMenu).setFont(new Font("Dialog", Font.PLAIN, 12));
//aboutCalc.setBorder(new BevelBorder(BevelBorder.RAISED));
aboutCalc.setBorder(LineBorder.createGrayLineBorder());
//aboutCalc.setActionCommand("Nothing here right now");
//Setting absolute positions for the buttons.
btn0.setBounds(50, 160, 35, 28);
btn1.setBounds(50, 130, 35, 28);
btn2.setBounds(90, 130, 35, 28);
btn3.setBounds(130, 130, 35, 28);
btn4.setBounds(50, 100, 35, 28);
btn5.setBounds(90, 100, 35, 28);
btn6.setBounds(130, 100, 35, 28);
btn7.setBounds(50, 70, 35, 28);
btn8.setBounds(90, 70, 35, 28);
btn9.setBounds(130, 70, 35, 28);
btnC.setBounds(180, 35, 63, 28);
btnCE.setBounds(115, 35, 63, 28);
btnBkpSpc.setBounds(50, 35, 63, 28);
btnPlus.setBounds(170, 160, 35, 28);
btnMinus.setBounds(170, 130, 35, 28);
btnMultiply.setBounds(170, 100, 35, 28);
btnDivide.setBounds(170, 70, 35, 28);
btnEquals.setBounds(210, 160, 35, 28);
btnPeriod.setBounds(130, 160, 35, 28);
btnPlusMinus.setBounds(90, 160, 35, 28);
btnMC.setBounds(8, 70, 35, 28);
btnMR.setBounds(8, 100, 35, 28);
btnMS.setBounds(8, 130, 35, 28);
btnMPlus.setBounds(8, 160, 35, 28);
btnSqrt.setBounds(210, 70, 35, 28);
btnMod.setBounds(210, 100, 35, 28);
btnOneOverX.setBounds(210, 130, 35, 28);
// btn7.addKeyListener(this);
try
UIManager.setLookAndFeel("javax.swing.plaf.metal.MetalLookAndFeel");
SwingUtilities.updateComponentTreeUI(this);
catch (Exception e)
System.out.println("Could not load Metal Look and Feel");
public void keyReleased(KeyEvent e)
//btn1 = txtArea.getRegisteredKeyStrokes();
// System.out.println(1);
// keyTyped();
public void keyPressed(KeyEvent e)
//if (e.getActionCommand().equals("1"));
//(e.getKeyText().compareTo("1"));
//(e.getKeyCode().equals("1"));
//else
System.out.println("Error");
//keyTyped();
public void keyTyped(KeyEvent e)
//displayInfo(e, "KEY TYPED: ");
System.err.println("KeyTyped >>> " + e.KEY_TYPED);
//keyEvent.keyTyped();
// e.KEY_TYPED;
/* protected void displayInfo (KeyEvent e, string s)
{KeyCodeString;
int keyCode = e.getKeyCode();
keyCodeString = "key code " + keyCode
+ "("
+ KeyEvent.getKeyText(keyCode);
public void actionPerformed(ActionEvent e)
stringInput = e.getActionCommand();
System.out.println("First stringInput action performed>>" +stringInput);
System.out.println("First pre action performed>>" +pre);
if (stringInput == "C")
operand1 = "";
operand2 = "";
var1 = 0;
var2 = 0;
var1 = result;
txtArea.setText("0.");
flag = false;//to force the operations to jump to operand 1 and go through the loop as normal
pre = "";
if (stringInput == "CE")
operand2 = "";
var2 = 0;
txtArea.setText("0.");
flag = true;//to force the operations to jump to operand 1 and go through the loop as normal
if (stringInput == "MR")
if (var1 != 0)
txtArea.setText(Double.toString(var1));
mArea.setText("M");
System.err.println("mem@operand1 >> "+ mem );
else if (var2 != 0)
txtArea.setText(Double.toString(var2));
mArea.setText("M");
System.err.println("mem @ mR else>> "+ mem );
if (stringInput == "MS")
mArea.setText("M");
if (operand1 != "")
mem = var1;
else if (operand2 != "")
mem = var2;
else
mem = 0;
if (stringInput == "MC")
mArea.setText("");//to clear the text area display
mem = 0;//to reset the variable
if (stringInput == "M+")
mArea.setText("M");
flag = true;//to force the operations to jump to operand 2 and go through the loop as normal
if (stringInput == "=")
//result = evaluate();
txtArea.setText(Double.toString(result));
System.out.println("Equals>>" +stringInput);
System.out.println("Equals>>" +pre);
System.err.println("The flag at equals is " + flag);
if (stringInput == "+"||stringInput == "-"||stringInput == "/"||
stringInput == "*"||stringInput == "=")
pre = pre.concat(stringInput);
System.out.println("Second action perfo/check for operator>>" +stringInput);
System.out.println("Second pre action perfo/check for operator>>" +pre);
operand2 = "";
System.err.println("The flag at +,- etc is " + flag);
if(!flag &&(stringInput == "*"|| stringInput == "/"))
var2 = 1;
stringInput = "";
flag = true;
if(!flag)
stringInput = pre;
System.out.println("if flag true/stringInput" +stringInput);
System.out.println("flag true/pre" +pre);
else
//These statements extract the operator
stringInput = pre.valueOf(pre.charAt(pre.length()-2));
ch = pre.charAt(pre.length()-2);
System.out.println("@ position -2 stringInput" + pre.valueOf(pre.charAt(pre.length()-2)));
System.out.println("@ position -2 pre" + pre.charAt(pre.length()-2));
result = evaluate();
var2 = 0;
operand2 = "";
txtArea.setText(Double.toString(result));
System.out.println("Total is " + result);
flag = true;
if(!flag &&(stringInput == "*"|| stringInput == "/"))
var2 = 1;
stringInput = "";
flag = true;
if (stringInput == "%")
//evaluate();
txtArea.setText(Double.toString(result));
System.err.println("mem @ mR else>> "+ result + " %" );
if (stringInput == "1/x")
if (operand1 != "")
txtArea.setText(Double.toString(1/var1));
//System.err.println("mem@operand1 >> "+ mem );
else if (operand2 != "")
operand2 = "";
txtArea.setText(Double.toString(1/var2));
//System.err.println(">> "+ mem );
if (Character.isDigit(stringInput.charAt(0))||stringInput == ".")
System.out.println(operand1);
if (stringInput == "." && operand1 == "")
operand1 = "0";
System.out.print("fail op1");
if (stringInput == "." && operand2 == "")
System.out.print("fail op2");
operand2 = "0";
if (flag==false)
operand1 = operand1.concat(stringInput);
result = Double.parseDouble(operand1);
System.out.println("op1 =>" + operand1);
txtArea.setText(operand1);
//result = var1;
System.out.println("result after var1 = result " + result);
else
operand2 = operand2.concat(stringInput);
var2 = Double.parseDouble(operand2);
//var2 = vMod;
System.out.println("op2 =>" + operand2);
txtArea.setText(" ");//to clear the text area
txtArea.setText(operand2);//to display the second number if (operators == "+")
System.out.println("result after var2 " + result);
public double evaluate()
if (ch == '+' )
result = result + var2;
if (ch == '-' )
result = result - var2;
if (ch == '/' )
result = result / var2;
if (ch == '*' )
result = result * var2;
if (ch == '%')
var2 = Double.parseDouble(operand2);
result = result/vMod*100;
System.out.println("% "+ result);
return result;
public static void main(String [] args)
Calctester x = new Calctester();
} -
Need help with Java app for user input 5 numbers, remove dups, etc.
I'm new to Java (only a few weeks under my belt) and struggling with an application. The project is to write an app that inputs 5 numbers between 10 and 100, not allowing duplicates, and displaying each correct number entered, using the smallest possible array to solve the problem. Output example:
Please enter a number: 45
Number stored.
45
Please enter a number: 54
Number stored.
45 54
Please enter a number: 33
Number stored.
45 54 33
etc.
I've been working on this project for days, re-read the book chapter multiple times (unfortunately, the book doesn't have this type of problem as an example to steer you in the relatively general direction) and am proud that I've gotten this far. My problems are 1) I can only get one item number to input rather than a running list of the 5 values, 2) I can't figure out how to check for duplicate numbers. Any help is appreciated.
My code is as follows:
import java.util.Scanner; // program uses class Scanner
public class Array
public static void main( String args[] )
// create Scanner to obtain input from command window
Scanner input = new Scanner( System.in);
// declare variables
int array[] = new int[ 5 ]; // declare array named array
int inputNumbers = 0; // numbers entered
while( inputNumbers < array.length )
// prompt for user to input a number
System.out.print( "Please enter a number: " );
int numberInput = input.nextInt();
// validate the input
if (numberInput >=10 && numberInput <=100)
System.out.println("Number stored.");
else
System.out.println("Invalid number. Please enter a number within range.");
// checks to see if this number already exists
boolean number = false;
// display array values
for ( int counter = 0; counter < array.length; counter++ )
array[ counter ] = numberInput;
// display array values
System.out.printf( "%d\n", array[ inputNumbers ] );
// increment number of entered numbers
inputNumbers++;
} // end close ArrayYikes, there is a much better way to go about this that is probably within what you have already learned, but since you are a student and this is how you started, let's just concentrate on fixing what you got.
First, as already noted by another poster, your formatting is really bad. Formatting is really important because it makes the code much more readable for you and anyone who comes along to help you or use your code. And I second that posters comment that brackets should always be used, especially for beginner programmers. Unfortunately beginner programmers often get stuck thinking that less lines of code equals better program, this is not true; even though better programmers often use far less lines of code.
// validate the input
if (numberInput >=10 && numberInput <=100)
System.out.println("Number stored.");
else
System.out.println("Invalid number. Please enter a number within range."); Note the above as you have it.
// validate the input
if (numberInput >=10 && numberInput <=100)
System.out.println("Number stored.");
else
System.out.println("Invalid number. Please enter a number within range."); Note how much more readable just correct indentation makes.
// validate the input
if (numberInput >=10 && numberInput <=100) {
System.out.println("Number stored.");
else {
System.out.println("Invalid number. Please enter a number within range.");
} Note how it should be coded for a beginner coder.
Now that it is readable, exam your code and think about what you are doing here. Do you really want to print "Number Stored" before you checked to ensure it is not a dupe? That could lead to some really confused and frustrated users, and since the main user of your program will be your teacher, that could be unhealthy for your GPA.
Since I am not here to do your homework for you, I will just give you some advice, you only need one if statement to do this correctly, you must drop the else and fix the if. I tell you this, because as a former educator i know the first thing running through beginners minds in this situation is to just make the if statement empty, but this is a big no no and even if you do trick it into working your teacher will not be fooled nor impressed and again your GPA will suffer.
As for the rest, you do need a for loop inside your while loop, but not where or how you have it. Inside the while loop the for loop should be used for checking for dupes, not for overwriting every entry in the array as you currently have it set up to do. And certainly not for printing every element of the array each time a new element is added as your comments lead me to suspect you were trying to do, that would get real annoying really fast again resulting in abuse of your GPA. Printing the array should be in its own for loop after the while loop, or even better in its own method.
As for how to check for dupes, well, you obviously at least somewhat understand loops and if statements, thus you have all the tools needed, so where is the problem?
JSG -
Firefox not responding to keyboard input
I'm having issues with Firefox temporarily no longer responding to keyboard input.
I have two machines, both running Windows 7. On my laptop, I never have any issues but on my desktop, I find that Firefox sometimes blocks keyboard input. It will allow me to enter one character in any text field, and no more. Any further input is ignored. This applies to the address bar, the search box and any text fields in the displayed web page, in any tab. All keyboard navigation seems to also be ignored.
I've tried Reset Firefox and Safe Mode, they don't appear to change anything. I've also tried uninstalling Synergy and changing from my regular English-International keyboard layout to US English, but this still seems to occur. I am also running Workrave which can interrupt keyboard input, but since I can add 1 character, I suspect that Workrave is not the problem.
Sometimes it can seemingly be unblocked by pressing Start+F9, CTRL+SHIFT+ESC, restarting firefox or opening a new tab, but this seems to only be a temporary solution, the problem soon reoccurs. This bug has been present for some time, I first noticed it in v28 (although it may be even older), I am currently using v31.
One thing I've noticed is that it never occurs until after my screen has been locked at least once.
The trouble-shooting information attached will not be entirely accurate because I'm using my laptop to type this - Firefox is not accepting keyboard input right now on my desktop! However, the two environments are similar.
Thanks, TadhgSome have reported that pressing F9 and the Windows key simultaneously one or more times has worked to fix issues with the keyboard not working.
-
Kazakh keyboard input not works
Hi.
I'm can't figure out trouble with kazakh(cyrillic) input to text controls in Flex4.
I'm embedded unicode fonts, and "Copy->Paste" kazakh text from notepad into flash app works fine!
But i need to keyboard input. In my case ordinar cyrillic letters inputs normal, but kazakh-specific
letters (located in keyboard's 1234 and 7890 keys) not works - ? symbol displays.
Please, anyone help me. I'm wasting 2 weeks in attempt to resolve it.
P.S: FlexSDK 4.0.0.12321, FP 10.0.42.34, OS Windows.When you paste and it works, take the string and look at the charCodeAt() for each character in the string.
Then when you type, see if the keyDown event is reporting the same charCode or not.
Another test is to verify that your browser can allow those characters when typed into an HTML INPUT tag.
Hi!
When i'm pasting kazakh letters into textInput, flexApp shows correct charCodes, e.g.:
әіңғүұқөһ -> 1241 1110 1187 1171 1199 1201 1179 1257 1211
but when i'm typing this letters from keyboard, flex shows these charCodes:
?і??????? -> 63 1110 63 63 63 63 63 63 63
(cyrillic-kazakh letters located in place of 2,3,4,5,8,9,0,-,= symbols of keyboard, on simple click - lowercase, with ShiftKey - uppercase).
testing app code:
<?xml version="1.0" encoding="utf-8"?>
<s:Application xmlns:fx="http://ns.adobe.com/mxml/2009"
xmlns:s="library://ns.adobe.com/flex/spark"
xmlns:mx="library://ns.adobe.com/flex/mx" minWidth="955" minHeight="600">
<fx:Script>
<![CDATA[
import mx.controls.Alert;
protected function richeditabletext1_keyDownHandler(event:KeyboardEvent):void
protected function rt1_keyUpHandler(event:KeyboardEvent):void
ttt.text = "";
for (var i:uint = 0; i<rt1.text.length; i++){
ttt.text = ttt.text+" "+ rt1.text.charCodeAt(i);
]]>
</fx:Script>
<fx:Style>
@namespace s "library://ns.adobe.com/flex/spark";
@namespace mx "library://ns.adobe.com/flex/mx";
@font-face {
src: url("arialuni.ttf"); /* Embed from file */
fontFamily:"Thai_font";
/*unicodeRange:"Cyrillic";*/
unicodeRange: U+0400-04F9;
cff-hinting:none;
embeddAsCFF:true;
.test{
font-family:Thai_font;
</fx:Style>
<s:TextInput id="ttt" width="100%" fontFamily="Arial Unicode MS"/>
<s:TextInput id="rt1" x="562" y="243" text="RichEditableText" width="100%" height="500" enabled="true"
editable="true" fontSize="18" keyDown="richeditabletext1_keyDownHandler(event)"
keyUp="rt1_keyUpHandler(event)"
direction="ltr"
styleName="test"/>
</s:Application> -
Keyboard input delay Flex/AIR
I've build an AIR desktop app that uses an USB barcode scanner. To capture the token provided by the barcode scanner an input field is used.
When testing the barcode input was only partially captured by the scanner. This was caused by the barcode scanner's input coming in the fast. Increasing the key stroke delay of the barcode scanner (config tool from motorola) solved the problem however this is not ideal.
Does anyone has experience with this type of problems? What is an approach to solve this? Maybe by writing an Java compagnion app that captures the keyboard input?I just ran into this same problem. Our users are scanning barcodes from various labels using various types of scanners (changing the delay using scanner software wasn't an option). We also have to allow them to scan to a TextInput within a DataGrid, which created even more problems. There were 2 very interesting things I learned in coming up with a solution for this one:
1. As mentioned previously, the scanner inputs the data so quickly that the enter key event is often processed before the change event for the text. I tried several solutions (like trying to force the change event before the enter key is processed), but learned that the best solution was just to add the delay as mentioned in previous posts.
2. When adding to a DataGrid control, I learned that both the DataGrid's & the TextInput's key down events are fired by the same SystemManager event. Though you can override the TextInput's keyDownHandler, you can't override the DataGrid's because it's a private method. So, even though my delay was being processed in the TextInput, the DataGrid was forcing control away from it and moving to the next item in the grid. To get around this one, I had to stop propagation of the event from the TextInput, then re-start the DataGrid's event once the delay was complete. I also had to process a focus-out event to get it to move to the next item in the DataGrid.
Here's the code I used inside a custom TextInput control to handle processing both stand-alone and inside a DataGrid:
override protected function keyDownHandler(event:KeyboardEvent):void
// If the enter key was pressed, then we need to add a delay.
// Barcode scanners quite often process the enter key before the TextInput
// control has time to finish processing all the text. (e.g., Instead of
// getting 12345 as a text entry, you could get 123 or 1234.)
if (event.charCode == Keyboard.ENTER)
// If this is the first time we've processed the enter key, we need to
// add the delay.
if (_keyboardEvent == null)
_keyboardEvent = new KeyboardEvent(event.type, event.bubbles,
event.cancelable, event.charCode, event.keyCode, event.keyLocation,
event.ctrlKey, event.altKey, event.shiftKey);
event.stopImmediatePropagation();
barcodeTimer(_keyboardEvent);
return;
// If the enter key is pressed while we are still in the delay, ignore
// it.
else if (_keyboardEvent != null && _keyboardEvent != event)
return;
// If the delay is complete, then we need to restart events related to
// the enter key so the control is handled properly.
else
super.keyDownHandler(event);
// If the TextInput is inside a DataGrid, then we need to dispatch the
// DataGrid's key down event. We also need to make sure the proper
// focus change happens (since this was stopped in the original event
// propagation).
if (parent != null && parent.parent != null &&
parent.parent is mx.controls.DataGrid)
parent.parent.dispatchEvent(event);
dispatchEvent(new FocusEvent(FocusEvent.KEY_FOCUS_CHANGE, true,
false, null, event.shiftKey, Keyboard.TAB));
_keyboardEvent = null;
return;
super.keyDownHandler(event);
* This is a copy of the keyboard event to be processed once the barcode
* delay is complete.
private var _keyboardEvent:KeyboardEvent = null;
* This method launches a timer of sufficient length to allow barcode
* scanner text to be processed before it re-launches the keyboard event.
* @param event This is the key-down event to be restarted once the timer is
* complete.
private function barcodeTimer(event:KeyboardEvent):void
var t:Timer = new Timer(30, 1); // 30 ms
t.addEventListener(TimerEvent.TIMER,
function():void
keyDownHandler(event);
t.start(); -
Satellite A100 Keyboard input language does not match the physical keyboard
Sorry.
Actually this is the first row:
& é " ' ( - è _ ç * ) =
Regards,
Leonardo
I have a SATELLITE A 100 laptop (Model PSAARE-02X01TFR) with french (I think) QWERTY keyboard here and cannot figure out how to set it in Win XP.
It has these chars on top row:
(Numbers are shifted)
The second row has:
q w e r t y u i o p ^ $
The third:
q s d f g h j k l : ù *
The fourth:
z x c v b n m ; , !
Any idea what is it and how do i set it up???
Thanks, LeonardoHi!
As Akuma said you can change the keyboard input language in control panel. Its very easy and takes only one minute to change it.
Check this!
If you have more questions, please let us know!! :)
Bye
Maybe you are looking for
-
Vendor account not picked in F110 payment run
Hi Sap Experts, i have assigned two payment methods to vendor master X,Y,which i do payment run for X for currency USD all the documents are picked for payment and when i run another payment run same time for Y for currency INR its not picking up in
-
Any ideas? Works fine in classic Yahoo mail. But in the "new" Yahoo mail, there is not even an option to open in new tab when I right click the message to be opened. Interestingly enough, I can right click open to new tab on any other link on the
-
I-Phone @ Inaugural - AT&T Fails Again - Damaging Apple Brand Name
Once again AT&T let down i-Phone users. Terrible coverage across Washington DC while my Blackberry friends enjoyed great service. We missed our ride at one point because AT&T system went down. In the coat check line at one Inaugural Ball I overheard
-
How do I turn off the Power button Lockout on my HPw1858 monitor?
How do I turn off the Power button lockout on my HPw1858 monitor? This question was solved. View Solution.
-
I thought Skype was free so why have I been charge...
I have just had a payment taken from my account by Skype. I have no idea what I'm paying for or why. I live on disability benefits and that is more than a weeks food money for something I have never used, don't want and thought was free. I now have n