Double click on the Go! Button to add an ActionListener. It should jump you into the code view. Here are some syntax differences comparing VB to Java: All statements end with either ; or { Single statements end with ; Anything that opens a new block of code, such as an If-Statement, While-Loop, Method, Class, etc. end with { End If / End / End anything is always replaced with } To do this: VB Java Create a variable Dim name as type type name; or or Dim name as type = value type name = value; Dim i as Integer = 0 int i = 0; Dim c as Character = char c = “T” ‘T’; Dim stuff as String = dude?” + vbCrLf String stuff = dude?\n”; “sup “sup To convert to 5 CInt(“5”) Integer.parseInt(“5”) “5” To convert 5 to Str(5) Integer.toString(5) “5” Get text from a txtInput.Text txtInput.getText() TextBox Set text into a txtInput.Text = stuff” txtInput.setText(“new stuff”) “new TextBox (i < 10) { Run a loop 10 While i < 10 times … … } End While String greeting = "hello"; Getting the second Dim greeting as String = “hello” greeting.charAt(1); letter of a string greeting(1) myArray.length Getting the length myArray.Count myString.length() of an Array / String myList.size() / etc. New Line vbCrLf “\n” Setting a Variable variable = variable = “newValue” “newValue” (= Operator) Checking if 2 things If i = 5 Then if (i == 5) { are equal VB Uses 1 equal sign // JAVA USES TWO EQUALS! ‘ End If } Now your goal is to write some code that makes the following output:
Double click on the Go! Button to add an ActionListener. It should jump you into the code view. Here are some syntax differences comparing VB to Java: All statements end with either ; or { Single statements end with ; Anything that opens a new block of code, such as an If-Statement, While-Loop, Method, Class, etc. end with { End If / End / End anything is always replaced with } To do this: VB Java Create a variable Dim name as type or Dim name as type = value Dim i as Integer = 0 Dim c as Character = “T” Dim stuff as String = “sup dude?” + vbCrLf type name; or type name = value; int i = 0; char c = ‘T’; String stuff = “sup dude?\n”; To convert “5” to 5 CInt(“5”) Integer.parseInt(“5”) To convert 5 to “5” Str(5) Integer.toString(5) Get text from a TextBox txtInput.Text txtInput.getText() Set text into a TextBox txtInput.Text = “new stuff” txtInput.setText(“new stuff”) Run a loop 10 times While i < 10 … End While (i < 10) { … } Getting the second letter of a string Dim greeting as String = “hello” greeting(1) String greeting = "hello"; greeting.charAt(1); Getting the length of an Array / String / etc. myArray.Count myArray.length myString.length() myList.size() New Line vbCrLf “\n” Setting a Variable (= Operator) variable = “newValue” variable = “newValue” Checking if 2 things are equal If i = 5 Then ‘ VB Uses 1 equal sign End If if (i == 5) { // JAVA USES TWO EQUALS! } Now your goal is to write some code that makes the following output:
CP12-JavaIntro.docx