I'm having a hard time removing data from my JTable. I've tried JTable .repaint(), setRowCount(0) , also model.removeRow(). I created print statements to see the row count when using setRowCount and the rows do become 0 however my table does not update. This is the last part of this project I need to implement. I'm not sure why my table isn't updating because I am altering the model with removeRow as well as setRowCount. If you guys could guide me in the right direction I would appreciate it.
public class TemplateGui extends JFrame {
private final ButtonGroup buttonGroup = new ButtonGroup();
private JTextField textField;
private static String [] sortedRoles_Flags,finalFlagsArr,finalHSArr;
private static String finalFlags="",finalHS="",columnToConvert="Result";
private Vector<String> SF,HS,column;
private JTable hotelSecurityTable,securityFlagsTable;
private DefaultTableModel hsTableModel,sfTableModel;
public TemplateGui(){
super("Galaxy Template Generator V1.0");
//column name
column = new Vector(Arrays.asList(columnToConvert));
getContentPane().setForeground(new Color(0, 0, 0));
getContentPane().setLayout(null);
getContentPane().setBackground(new Color(51, 51, 51));
//radio buttons
JRadioButton rdbtnNewRadioButton = new JRadioButton("Central User ");
rdbtnNewRadioButton.setFont(new Font("Tahoma", Font.BOLD, 11));
rdbtnNewRadioButton.setBackground(Color.WHITE);
buttonGroup.add(rdbtnNewRadioButton);
rdbtnNewRadioButton.setBounds(222, 75, 127, 36);
getContentPane().add(rdbtnNewRadioButton);
final JRadioButton rdbtnPropertyUser = new JRadioButton("Property User");
rdbtnPropertyUser.setFont(new Font("Tahoma", Font.BOLD, 11));
rdbtnPropertyUser.setBackground(Color.WHITE);
buttonGroup.add(rdbtnPropertyUser);
rdbtnPropertyUser.setBounds(222, 38, 127, 34);
getContentPane().add(rdbtnPropertyUser);
textField = new JTextField();
textField.setFont(new Font("Tahoma", Font.BOLD, 18));
textField.setBounds(10, 35, 53, 34);
getContentPane().add(textField);
textField.setColumns(10);
JLabel lblHotelSecurity = new JLabel("Hotel Security (H S)");
lblHotelSecurity.setHorizontalAlignment(SwingConstants.CENTER);
lblHotelSecurity.setFont(new Font("Tahoma", Font.BOLD, 13));
lblHotelSecurity.setBounds(10, 144, 189, 23);
lblHotelSecurity.setBackground(new Color(204, 204, 204));
lblHotelSecurity.setOpaque(true);
getContentPane().add(lblHotelSecurity);
JLabel label = new JLabel("Security Flags (S F)");
label.setHorizontalAlignment(SwingConstants.CENTER);
label.setFont(new Font("Tahoma", Font.BOLD, 13));
label.setBounds(222, 144, 372, 23);
label.setBackground(new Color(204, 204, 204));
label.setOpaque(true);
getContentPane().add(label);
JLabel lblEnterTemplateCode = new JLabel("ENTER TEMPLATE CODE");
lblEnterTemplateCode.setForeground(new Color(255, 255, 255));
lblEnterTemplateCode.setFont(new Font("Tahoma", Font.BOLD, 14));
lblEnterTemplateCode.setBounds(10, 9, 175, 23);
getContentPane().add(lblEnterTemplateCode);
JLabel lblSelectUserRole = new JLabel("SELECT USER ROLE LEVEL");
lblSelectUserRole.setForeground(new Color(255, 255, 255));
lblSelectUserRole.setFont(new Font("Tahoma", Font.BOLD, 14));
lblSelectUserRole.setBounds(222, 13, 195, 14);
getContentPane().add(lblSelectUserRole);
//Submit button action
Button button = new Button("Generate Template");
button.setFont(new Font("Dialog", Font.BOLD, 12));
button.setBackground(new Color(102, 255, 102));
button.setForeground(Color.BLACK);
button.setBounds(467, 83, 127, 41);
getContentPane().add(button);
button.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent arg0) {
Query excell = new Query();
//get template text
String template = textField.getText().toUpperCase();
System.out.println(template);
if(rdbtnPropertyUser.isSelected()){
try {
//property user was selected
excell.runProcess(1);
System.out.println("you selected Property user");
} catch (IOException e) {
e.printStackTrace();
}
}
else{
try {
//Central User was selected
excell.runProcess(2);
System.out.println("you selected central user");
} catch (IOException e) {
e.printStackTrace();
}
}
System.out.println("NOW WERE HERE");
//get static variables from Excel Query
for(int i = 0; i< Query.sortedGF.length; i++)
{
if(Query.sortedGF[i].contains(template)){
sortedRoles_Flags =Query.sortedGF[i].split(" ");
System.out.println("THIS RAN"+" :"+i);
break;
}
}
//add data to table
int j=1;
int sizeOfFlags = Query.securityFlags.length;
//Add HS to FinalHS Variable only if Yes
for(int i=0;i< sortedRoles_Flags.length+1-sizeOfFlags;i++)
{
if(sortedRoles_Flags[i].matches("Y|y|Y\\?|\\?Y|y\\?|\\?y"))
{
System.out.println("Hotel security:"+" "+sortedRoles_Flags[i]+" HS Added: "+Query.hotelSecurity[i]);
finalHS += Query.hotelSecurity[i]+"+";
System.out.println("Hotel security:"+" "+finalHS);
}
}
//add Security Flags to Final Flags
for(int i=(sortedRoles_Flags.length-sizeOfFlags+1);i< sortedRoles_Flags.length;i++)
{
finalFlags += Query.securityFlags[j]+"\t\t: "+ sortedRoles_Flags[i]+" + ";
j++;
}
//Leave open just incase they would prefer a text file for template in which case we just write it
System.out.println(finalFlags);
System.out.println(finalHS);
//Convert to String Arrays in order to add to our JTable
finalFlagsArr= finalFlags.split("\\+");
finalHSArr = finalHS.split("\\+");
for(int i=0; i <finalHSArr.length;i++)
finalHSArr[i].replaceAll(" ","");
hsTableModel.setRowCount(0);
for (String row : finalHSArr) {
hsTableModel.addRow(new Object[]{row});
}
sfTableModel.setRowCount(0);
for (String row : finalFlagsArr) {
sfTableModel.addRow(new Object[]{row});
}
}
});
//scroll panes for flags
JScrollPane scrollPaneHS = new JScrollPane();
scrollPaneHS.setHorizontalScrollBarPolicy(ScrollPaneConstants.HORIZONTAL_SCROLLBAR_ALWAYS);
scrollPaneHS.setBounds(10, 170, 189, 185);
getContentPane().add(scrollPaneHS);
JScrollPane scrollPaneSF = new JScrollPane();
scrollPaneSF.setHorizontalScrollBarPolicy(ScrollPaneConstants.HORIZONTAL_SCROLLBAR_ALWAYS);
scrollPaneSF.setBounds(222, 170, 372, 187);
getContentPane().add(scrollPaneSF);
//tables for updates
hsTableModel = new DefaultTableModel(HS,column);
hotelSecurityTable = new JTable(hsTableModel);
hotelSecurityTable.setBackground(new Color(255, 255, 255));
scrollPaneHS.setViewportView(hotelSecurityTable);
sfTableModel = new DefaultTableModel(SF,column);
securityFlagsTable = new JTable(sfTableModel);
scrollPaneSF.setViewportView(securityFlagsTable);
}
}
Update
my latest attempt. It seemed to work but not the second time around.
if(hsTableModel.getRowCount() !=0 && sfTableModel.getRowCount() !=0){
for(int i=0; i<hsTableModel.getRowCount();i++)
hsTableModel.removeRow(i);
for(int i=0; i<sfTableModel.getRowCount();i++)
sfTableModel.removeRow(i);
sfTableModel.fireTableRowsDeleted(0, sfTableModel.getRowCount()-1);
hsTableModel.fireTableRowsDeleted(0, hsTableModel.getRowCount()-1);
}
when using setRowCount and the rows do become 0 however my table does not update.
Since you are using a DefaultTableModel, the setRowCount(0) is the proper method to use to clear the model of all the entries. The should automatically repaint itself.
Create a simple SSCCE that demonstrates your problem. The SSCCE should consist of a JTable with data, and then a JButton to invoke the setRowCount() method.
Prove to yourself that the basic concept works and then determine why you real code doesn't. If the table does not repaint then it usually means you are invoking the setRowCount() method on a TableModel that has NOT be added to the JTable that is visible on the GUI.
Also, don't:
use Button. You should be using a JButton
use a null layout. Swing was designed to be used with Layout Managers.
setRowCount(0) works.
I was forgetting to reset the string Values of
finalHS =""; finalFlags=""; Therefore the table was printing out the values stored in the variable.
I had the variables obtain their data through += Method as seen below.
Next time I will SSCCE before posting.
for(int i=0;i< sortedRoles_Flags.length+1-sizeOfFlags;i++)
{
if(sortedRoles_Flags[i].matches("Y|y|Y\\?|\\?Y|y\\?|\\?y"))
{
System.out.println("Hotel security:"+" "+sortedRoles_Flags[i]+" HS Added: "+Query.hotelSecurity[i]);
finalHS += Query.hotelSecurity[i]+"+";
System.out.println("Hotel security:"+" "+finalHS);
}
}
//add Security Flags to Final Flags
for(int i=(sortedRoles_Flags.length-sizeOfFlags+1);i< sortedRoles_Flags.length;i++)
{
finalFlags += Query.securityFlags[j]+"\t\t: "+ sortedRoles_Flags[i]+" + ";
j++;
}
Related
I am new in java and trying to create a dashboard where I have N number of sensors and now i wants to show values of Humidity and temperature of each sensor in a separate panels . So firstly i have created N number of panels containing a JSlider and JThermometer for Humidity and temperature each. Now in a loop it reads the lines of outputs from arduino and i am trying to provide that values to that thermometers and sliders .
But i am not able to differentiate that output for which panel it is goin to set . even when i tried to set values to them it is not working at all.
Kindly give any idea how can i implement.
Thank you for help.
Java version - 18.0.1.1
IDE - Apache netbeans 14
static JTextField txtTemp, txtMois;
static JLabel lblTemp, lblMois;
static JSlider slider1, slider2;
static JThermometer th1, th2 ;
static JPanel JP1, JP ;
public void interfaces(){
///Here number of panels is 2
if(count1 > 0){
for(int i = 0 ; i<=count1 ; i++){
JP1 = myPanel(i,0,0);
add(JP1);
}
}
setVisible(true);
setTitle("Temperature and Humidity");
setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
setSize(1200,800);
getContentPane().setBackground(Color.lightGray);
setMinimumSize(new Dimension(350,450));
setLayout(null);
SerialPort[] AvailablePorts = SerialPort.getCommPorts();
SerialPort currPort = AvailablePorts[0];
for (SerialPort S : AvailablePorts) {
System.out.println("\n " + S.toString());
currPort = S;
}
int BaudRate = 9600;
int DataBits = 8;
int StopBits = SerialPort.ONE_STOP_BIT;
int Parity = SerialPort.NO_PARITY;
System.out.println("\n " + currPort.getSystemPortName());
currPort.setComPortParameters(BaudRate,
DataBits,
StopBits,
Parity);
currPort.setComPortTimeouts(SerialPort.TIMEOUT_READ_BLOCKING,
1000,
0);
currPort.openPort();
if (currPort.isOpen())
{
System.out.println("is Open ");
} else {
System.out.println(" Port not open ");
}
try {
while (true) {
try{input = new BufferedReader(new InputStreamReader(currPort.getInputStream()));
String Line1 = input.readLine();
int count = 0;
String[] Data = Line1.split(" ");
for(int i = 0; i < Data.length; i++){
count +=1;
String[] Final_data = Data[i].split(",");
double temp, mois;
try{ temp = Double.parseDouble(Final_data[0]);
mois = Double.parseDouble(Final_data[1]);
System.out.println("Temparature : " + temp);
System.out.println("Humidity : " + mois);
th1.setValue(temp);
th2.setValue(mois);
slider1.setValue((int) temp);
slider2.setValue((int) mois);
txtTemp.setText(String.valueOf(temp));
txtMois.setText(String.valueOf(mois));
}
catch(NumberFormatException e){
System.out.println(e.toString());
}
}
}
catch(SerialPortTimeoutException ex){
System.out.println(ex);
}
}
} catch (Exception e) {
e.printStackTrace();
}
currPort.closePort();
}
//MyPannel funaction
public static JPanel myPanel(int count, double temp, double mois){
JP = new JPanel();
int width = (count-1)*420;
test = new JTextField(String.valueOf(count));
test.setBounds(0, 0, 200, 20);
JP.add(test);
th1 = new JThermometer();
th1.setBounds(10, 50, 150,300);
th1.setValue(0);
th1.setBackground(new Color(0,0,0,0));
th1.setForeground(Color.white);
String color = th1.getBackground().toString();
slider1 = new JSlider(JSlider.VERTICAL,0,100,0);
slider1.setBounds(110, 60, 50, 230);
slider1.setMinorTickSpacing(2);
slider1.setMajorTickSpacing(10);
slider1.setPaintTicks(true);
slider1.setPaintLabels(true);
slider1.setForeground(Color.white);
slider1.setBackground(new Color(0,0,0,0));
lblTemp = new JLabel("TEMPERATURE",SwingConstants.CENTER);
lblTemp.setBounds(15,30,140,30);
lblTemp.setForeground(Color.WHITE);
lblTemp.setFont(new Font("Arial", Font.BOLD, 20));
lblTemp.setBackground(Color.getColor(color));
txtTemp = new JTextField();
txtTemp.setFont(new Font("Arial", Font.BOLD, 16));
txtTemp.setBounds(115,300,50,30);
th2 = new JThermometer();
th2.setBounds(210, 50, 150, 300);
th2.setValue(0);
th2.setBackground(new Color(0,0,0,0));
th2.setForeground(Color.white);
slider2 = new JSlider(JSlider.VERTICAL,0,100,0);
slider2.setBounds(310, 60, 50, 230);
slider2.setMinorTickSpacing(2);
slider2.setMajorTickSpacing(10);
slider2.setPaintTicks(true);
slider2.setPaintLabels(true);
slider2.setBackground(new Color(0,0,0,0));
slider2.setForeground(Color.white);
lblMois = new JLabel("HUMIDITY",SwingConstants.CENTER);
lblMois.setBounds(215,30,140,30);
lblMois.setFont(new Font("Arial", Font.BOLD, 20));
lblMois.setForeground(Color.WHITE);
txtMois = new JTextField();
txtMois.setFont(new Font("Arial", Font.BOLD, 16));
txtMois.setBounds(315,300,50,30);
JP.add(lblTemp);
JP.add(txtTemp);
JP.add(lblMois);
JP.add(txtMois);
JP.add(th1,BorderLayout.CENTER);
JP.add(slider1);
JP.add(slider2);
JP.add(th2,BorderLayout.CENTER);
JP.setBounds(width, 20, 400, 400);
JP.setVisible(true);
JP.setLayout(new java.awt.BorderLayout());
JP.validate();
//JP.add(txt);
return JP;
}
//and arduino output will be like this..
29.5,56.9 25.5,40.3
29.5,54,8 25.5,40.0
so on...
I am currently creating a database that uses information from IMDB and Rotten Tomatoes. In the printout of the data (in a GUI Frame), I have to list the URL to the poster image of the movie.
My question is this: Instead of printing the image URL, is there a way to use the URL to show the image WITHOUT having the image stored locally?
Here's the code I have to display the data retrieved from mySQL (It works, I just want the URL to show as an image instead of the link):
public void mouseClicked(MouseEvent e) {
JFrame frame3 = new JFrame("Query 1: Top Movies");
frame3.setBackground(Color.BLACK);
frame3.setSize(new Dimension(1500,1500));
frame3.setVisible(true);
frame3.setDefaultCloseOperation(JFrame.HIDE_ON_CLOSE);
System.out.println("frame created");
try {
loadConnection();
//create query
System.out.println("Connection loaded...");
String sql = "SELECT M.TITLE,M.YEAR,M.RTAUDIENCESCORE,M.IMDBPICTUREURL FROM MOVIES AS M ORDER BY RTAUDIENCESCORE DESC,TITLE LIMIT 10";
//prepares statement for execution
java.sql.PreparedStatement ps = con.prepareStatement(sql);
ResultSet rs = ps.executeQuery();
System.out.println("Query Successful!");
//create labels for output
JLabel l1, l2, l3, l4;
JTextField title, year, RTscore, IMDBURL;
//labels
l1 = new JLabel("Title");
l2 = new JLabel("Year");
l3 = new JLabel("RT Audience Score");
l4 = new JLabel("IMDB Picture URL");
l1.setBounds(20, 20, 150, 20);
l2.setBounds(200, 20, 150, 20);
l3.setBounds(380, 20, 150, 20);
l4.setBounds(560, 20, 150, 20);
frame3.add(l1);
frame3.add(l2);
frame3.add(l3);
frame3.add(l4);
System.out.println("Frames added...");
int y = 50;
while (rs.next()) {
//Text fields
title = new JTextField();
year = new JTextField();
RTscore = new JTextField();
IMDBURL = new JTextField();
title.setText(rs.getString(1));
year.setText(rs.getString(2));
RTscore.setText(rs.getString(3));
IMDBURL.setText(rs.getString(4));
title.setBounds(20, y, 150, 20);
year.setBounds(200, y, 150, 20);
RTscore.setBounds(380, y, 150, 20);
IMDBURL.setBounds(560, y, 150, 20);
y+=30;
frame3.add(title);
frame3.add(year);
frame3.add(RTscore);
frame3.add(IMDBURL);
}
JLabel jLabelObject = new JLabel();
jLabelObject.setIcon(new ImageIcon(IMDBURL))
In your case you will have edit your while loop and add new label which will represent image.
frame3.add(title);
frame3.add(year);
frame2.add(RTscore);
frame3.add(jLabelObject);
I have used the following code to insert data into the mongodb database.....the problem with this i have to explicitly specify the data to be entered but however I need to do it dynamically...in the sense using a GUI, whatever has been entered int the text box must be put into the database.
private void initialize() {
frame = new JFrame();
frame.setBounds(100, 100, 512, 355);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.getContentPane().setLayout(null);
JLabel lblNewLabel = new JLabel("Name");
lblNewLabel.setBounds(42, 33, 95, 30);
frame.getContentPane().add(lblNewLabel);
JLabel lblNewLabel_1 = new JLabel("Manufacturer");
lblNewLabel_1.setBounds(42, 74, 80, 30);
frame.getContentPane().add(lblNewLabel_1);
textField = new JTextField();
textField.setBounds(147, 33, 122, 25);
frame.getContentPane().add(textField);
textField.setColumns(10);
textField_1 = new JTextField();
textField_1.setBounds(147, 79, 122, 25);
frame.getContentPane().add(textField_1);
textField_1.setColumns(10);
JButton btnInsert = new JButton("Insert");
btnInsert.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent arg0) {
MongoClient mongoClient = null;
DBCursor cursor = null;
try {
mongoClient = new MongoClient( "localhost" , 27017 );
DB db = mongoClient.getDB( "sample" );
DBCollection coll = db.getCollection("sample");
BasicDBObject doc = new BasicDBObject("title", "MongoDB").
append("name","a" ).
append("manufacturer", "b").
append("colour", "c").
append("price", "d");
coll.insert(doc);
}catch(Exception e){
System.err.println( e.getClass().getName() + ": " + e.getMessage() );}
}
});
btnInsert.setBounds(148, 223, 89, 23);
frame.getContentPane().add(btnInsert);
JLabel lblNewLabel_2 = new JLabel("Colour");
lblNewLabel_2.setBounds(42, 127, 65, 25);
frame.getContentPane().add(lblNewLabel_2);
textField_2 = new JTextField();
textField_2.setBounds(147, 129, 122, 25);
frame.getContentPane().add(textField_2);
textField_2.setColumns(10);
JLabel lblNewLabel_3 = new JLabel("Price");
lblNewLabel_3.setBounds(37, 175, 70, 25);
frame.getContentPane().add(lblNewLabel_3);
textField_3 = new JTextField();
textField_3.setBounds(147, 177, 122, 25);
frame.getContentPane().add(textField_3);
textField_3.setColumns(10);
}
}
"i have a front end which has 4 text boxes saying "name","manufacturer","colour" and "price"....so whatever i enter in the text box should be put into the database....however in the above code insertion can be done only by explicitly specifying the values....so i need to change this for a generlized method"
Just change it to something like:
String name = nameField.getText();
String manufacturer = manufacturerField.getText();
String color = colorField.getText();
String price = priceField.getText();
BasicDBObject doc = new BasicDBObject("title", "MongoDB").
append("name", name ).
append("manufacturer", manufacturer).
append("colour", color).
append("price", price);
coll.insert(doc);
Is that what you're looking for?
How can I declare JCheckBox so that when it's checked it will change the JLabel text to uppercase?
I've been trying many things yet nothing works
public void itemStateChanged(ItemEvent e) {
Font f = null;
if(Bold.isSelected() && Italic.isSelected())
f = new Font("Serif", Font.BOLD + Font.ITALIC, 14);
else if(Bold.isSelected())
f = new Font("Serif", Font.BOLD, 14);
else if(Italic.isSelected())
f = new Font("Serif", Font.ITALIC, 14);
if(Capitalized.isSelected()){
}
label3.setFont(f);
}
What should put inside if(Capitalized.isSelected())?
Have you tried getting the text, then calling toUpperCase() on it:
label3.setText(label3.getText().toUpperCase());
I have this GUI:
I would like after I enter a number in the Length of hot tub text box for that number to be automatically entered into the Width of hot tub text box, but only if the Round Tub radio button is selected.
public void createHotTubs()
{
hotTubs = new JPanel();
hotTubs.setLayout(null);
labelTubStatus = new JTextArea(6, 30);
hotTubs.add(labelTubStatus);
JLabel lengthLabel = new JLabel(
"Length of hot tub(ft):");
lengthLabel.setBounds(10, 15, 260, 20);
hotTubs.add(lengthLabel);
hotTubLengthText = new JTextField();
hotTubLengthText.setBounds(180, 15, 150, 20);
hotTubs.add(hotTubLengthText);
JLabel widthLabel = new JLabel(
"Width of hot tub(ft):");
widthLabel.setBounds(10, 40, 260, 20);
hotTubs.add(widthLabel);
hotTubWidthText = new JTextField();
hotTubWidthText.setBounds(180, 40, 150, 20);
hotTubs.add(hotTubWidthText);
JLabel depthLabel = new JLabel(
"Average depth the hot tub(ft):");
depthLabel.setBounds(10, 65, 260, 20);
hotTubs.add(depthLabel);
hotTubDepthText = new JTextField();
hotTubDepthText.setBounds(180, 65, 150, 20);
hotTubs.add(hotTubDepthText);
JLabel volumeLabel = new JLabel("The hot tub volume is:(ft ^3");
volumeLabel.setBounds(10, 110, 260, 20);
hotTubs.add(volumeLabel);
hotTubVolumeText = new JTextField();
hotTubVolumeText.setBounds(180, 110, 150, 20);
hotTubVolumeText.setEditable(false);
hotTubs.add(hotTubVolumeText);
final JRadioButton rdbtnRoundTub = new JRadioButton("Round Tub");
rdbtnRoundTub.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent arg0)
{
hotTubWidthText.setEditable(false);
}
});
rdbtnRoundTub.setSelected(true);
rdbtnRoundTub.setBounds(79, 150, 109, 23);
hotTubs.add(rdbtnRoundTub);
JRadioButton rdbtnOvalTub = new JRadioButton("Oval Tub");
rdbtnOvalTub.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent arg0)
{
hotTubWidthText.setEditable(true);
}
});
rdbtnOvalTub.setBounds(201, 150, 109, 23);
hotTubs.add(rdbtnOvalTub);
ButtonGroup radioBtnGroup = new ButtonGroup();
radioBtnGroup.add(rdbtnRoundTub);
radioBtnGroup.add(rdbtnOvalTub);
JButton btnCalculateVlmn = new JButton("Calculate Volume");
btnCalculateVlmn.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent arg0)
{
double width = 0, length = 0, depth = 0, volume = 0;
String lengthString, widthString, depthString;
lengthString = hotTubLengthText.getText();
widthString = hotTubWidthText.getText();
depthString = hotTubDepthText.getText();
depth = Double.valueOf(depthString);
length = Double.valueOf(lengthString);
width = Double.valueOf(widthString);
try
{
if (rdbtnRoundTub.isSelected())
{
volume = length * width * depth;
}
else
{
volume = Math.PI * length * width / 4 * depth;
}
DecimalFormat formatter = new DecimalFormat("#,###,###.###");
hotTubVolumeText.setText("" + formatter.format(volume));
}
catch (NumberFormatException e)
{
labelTubStatus
.setText("Enter all three numbers!!");
}
}
});
Add a focus listener to your length text field when it loses focus and the round tub is selected, compute and set the the width.