Keith Spriggs

Greenhorn
+ Follow
since Jul 19, 2012
Merit badge: grant badges
For More
Cows and Likes
Cows
Total received
0
In last 30 days
0
Total given
0
Likes
Total received
0
Received in last 30 days
0
Total given
0
Given in last 30 days
0
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by Keith Spriggs

Hi Guys,
Here is a puzzler, every time I create a group of radio buttons in SWT/JFace, the first button is always true, but if create a standard button and call it to reset the radio button it will reset to being false.
I would like it to be set to false as default.
Has any encountered a problem like this and how to solve it?
Thanks in advance

10 years ago
I presume a couple of things here.
1st is that theFlag is already set to false


2nd why don't you set the button to setenabled = false for the create team
10 years ago
There is another way
Look at the window builder add on for eclipse it gives very good wysiwyg editor.
10 years ago
Hi Guys,
Need a helping hand.
I'm trying to strech my limits I have no problem doing the following in javascript, but I'm trying to push my self into learning some REST.
What i'm trying to do is create a html interface that sends two numbers into a rest web services and then performs a calculation on those values.
There is no problem with the service itself and currently the result is displayed on a new web page.
What I'm trying to do is to get the result from the web service back onto the same page as the one the called it.
here is the code

Here is the html


and here is the rest or jax-rs


it's configured through netbeans and glasssfish server
I would appreciate any help
Keith
11 years ago
Thanks for the feedback.
I am the first to admit that the code is really brutal and it needs to be tidied up, big time.

The reason why I used the while loops is to get control from the key press. I found that without the while loops there would be no returns back from the called class. When I ran the program it skipped over waiting for a return from the called method which was a gui.
I know the correct method would be to use the invoke later and invoke and wait commands. However, I have been looking for examples in how to use these with called methods, but I haven't found an examples of this.
11 years ago
Hi guys,
This problem has me absolutely stumped, and even a couple of people I have shown it to.
If I leave in an system.out.println statement given the current state of a boolean expression it will allow me to call another object which creates a frame.
If I take it out, then it doesn't call the next object.

Before, I go on I would like to apologise for the poor code, but it generally works.

This is the main method


This is the method is being called


If anybody could suggest any slightly better code I would appreciate it.
11 years ago
Hi guys,
I need a bit of help with this one.

What I want to do is report when key has pressed.

The issue is that do have I have to specify all possible keys individually or is there a method or some code that allows me to do this.

I have a method that needs to send back a string to the user.
11 years ago
Hi Guys
This is the code for the main class
Thanks for all the help and advice.



This is the code for the called class
11 years ago
I managed to get a working solution
I will post it up tomorrow morning so it can be evaluated upon.
11 years ago
Each button has the line which I missed out on


button1.addActionListener(this);
button2.addActionListener(this);
button3.addActionListener(this);

11 years ago
This is the same code that is written for the command line.


package John;

public class Creamy {


public static void main(String[] args)
{
Gormy blue = new Gormy();
char choice = blue.getSelect();

switch(choice)
{
case 'a' : System.out.println("German Car");
break;
case 'b' : System.out.println("British Car");
break;
case 'c' : System.out.println("Japanese Car");
break;
default : System.out.println("No car Selected");
}
}
}


And the subMenu looks like

package John;

import java.util.Scanner;

public class Gormy
{
private Scanner sc;

public Gormy()
{

}

private void printDetail()
{
System.out.println("Please choose a car");
System.out.println("choose a : BMW");
System.out.println("choose b : Jaguar");
System.out.println("choose c : Lexus");
}

private char getCharacter()
{
sc = new Scanner(System.in);

return sc.next().charAt(0);
}

public char getSelect()
{
printDetail();
return getCharacter();
}
}


this works perfectly and it what I want the GUI to mimic.
the reason why I don't want to use dailog boxes which work fine is that I plan to implement more features at a later stage.
11 years ago
The code for the sub class is as follows


package John;

import java.awt.event.*;

import javax.swing.*;

public class Tiny extends JFrame implements ActionListener
{
private JLabel label1;
private JFrame frame1;
private JButton button1;
private JButton button2;
private JButton button3;
private char select;

public Tiny()
{
createFrame();
createLabel();
createButton1();
createButton2();
createButton3();
//actionPerformed(e1);
}

private void createFrame()
{
frame1 = new JFrame("Select Cars");
frame1.setSize(300, 400);
frame1.setLocation(350, 250);
frame1.setPreferredSize(null);
frame1.setLayout(new java.awt.GridLayout(4, 1));
frame1.setVisible(true);
frame1.setDefaultCloseOperation(EXIT_ON_CLOSE);
}

private void createLabel()
{
label1 = new JLabel("Select a car", SwingConstants.CENTER);
label1.setSize(300, 100);
frame1.add(label1);
}

private void createButton1()
{
button1 = new JButton("Bmw");
button1.setSize(300, 100);
frame1.add(button1);
}

private void createButton2()
{
button2 = new JButton("Jaguar");
button2.setSize(300, 100);
frame1.add(button2);
}

private void createButton3()
{
button3 = new JButton("Lexus");
button3.setSize(300, 100);
frame1.add(button3);
}

@Override
public void actionPerformed(ActionEvent e)
{
if (e.getSource() == button1)
select = 'a';
else
if(e.getSource() == button2)
select = 'b';
else
if(e.getSource() == button3)
select = 'c';
else
select = 'd';
}

public char getSelect()
{
return select;
}
}



The code for the calling class is as follows

package John;

public class Creamy {


public static void main(String[] args)
{
Tiny bear = new Tiny();

char choice = bear.getSelect();

switch(choice)
{
case 'a' : System.out.println("German Car");
break;
case 'b' : System.out.println("British Car");
break;
case 'c' : System.out.println("Japanese Car");
break;
default : System.out.println("No car Selected");
}
}

}

11 years ago
The GUI method is called.
This brings up a menu of buttons.
The User selects the button and a char is returned to the method that calls it.
11 years ago
I'll explain a bit more. The main method calls the sub method which asks the user to make a choice between either BMW or Lexus.
This is displayed as a GUI Menu.
The GUI would then return either a or b to the main which then will go into a conditional statement for further action.
11 years ago
I prefer to use the scanner method if you are using the command line method

If on the other hand if you are using GUI then the parse method would be bettered used

11 years ago