I need some help with my code. What i need it to do is everytime a page is added to the Java Book different data needs to be on the page every time. I've tried it a number of different ways and i just can't work it out!
Here's my code:
dataBase data = new dataBase();
int userCountAmount = data.getAmountOfUsers();
Book bk = new Book();
PrinterJob PJ = PrinterJob.getPrinterJob();
String[] pupilName = new String[userCountAmount];
String[] parentsName = new String[userCountAmount];
int parCount = 0;
int pupCount = 0;
public void print2() {
System.out.println(pupilName.length);
System.out.println(parentsName.length);
System.out.println(userCountAmount);
String[] custData = processData(data.getAllCustomers());
PageFormat portrait = PJ.defaultPage();
int pupNameCount = 0;
int parNameCount = 0;
portrait.setOrientation(PageFormat.PORTRAIT);
for (int i = 0; i < userCountAmount; i++) {
pupilName[i] = custData[pupNameCount];
parentsName[i] = custData[parNameCount];
System.out.println(custData[pupNameCount] + " " + custData[parNameCount]);
pupNameCount = pupNameCount + 13;
parNameCount = parNameCount + 13;
bk.append(new IntroPage(), PJ.defaultPage());
parCount++;
pupCount++;
System.out.println(parCount+" " + pupCount);
}
// setWindow();
//PageFormat PF = PJ.pageDialog(PJ.defaultPage());
PJ.setPageable(bk);
// PJ.setPrintable((Printable) this);
boolean doPrint = PJ.printDialog();
//JOptionPane.showMessageDialog(null, doPrint);
if (doPrint) {
try {
PJ.print();
} catch (PrinterException ex) {
JOptionPane.showMessageDialog(null, ex.getMessage());
}
}
}
private class IntroPage implements Printable {
/**
* Method: print
* <p>
*
* #param g
* a value of type Graphics
* #param pageFormat
* a value of type PageFormat
* #param page
* a value of type int
* #return a value of type int
*/
public int print(Graphics g, PageFormat pageFormat, int page) {
//--- Create the Graphics2D object
Graphics2D g2d = (Graphics2D) g;
//--- Translate the origin to 0,0 for the top left corner
g2d.translate(pageFormat.getImageableX(), pageFormat.getImageableY());
//--- Set the default drawing color to black and get date
g2d.setPaint(Color.black);
DateFormat dateFormat = new SimpleDateFormat("dd/MM/yyyy");
Date date = new Date();
//draw tables
g2d.setPaint(Color.darkGray);
Rectangle2D.Double invoiceOut = new Rectangle2D.Double(10, 200, 400, 280);
Rectangle2D.Double invoiceDesc = new Rectangle2D.Double(10, 200, 200, 280);
Rectangle2D.Double invoiceSess = new Rectangle2D.Double(10, 200, 260, 280);
Rectangle2D.Double invoiceRate = new Rectangle2D.Double(10, 200, 330, 280);
Rectangle2D.Double invoiceTitle = new Rectangle2D.Double(10, 200, 400, 20);
Rectangle2D.Double totalAmount = new Rectangle2D.Double(340, 480, 70, 20);
g2d.draw(invoiceOut);
g2d.draw(invoiceDesc);
g2d.draw(invoiceSess);
g2d.draw(invoiceRate);
g2d.draw(invoiceTitle);
g2d.draw(totalAmount);
//table title strings
String descrp = "Description:";
String sesh = "Sessions:";
String rate = "Rate:";
String amount = "Amount:";
String titleText = "INVOICE";
String totalAmountString = "Total Amount:";
//Address Strings
String printDate = "Print Date: " + String.valueOf(dateFormat.format(date));
String line1Text = "16 here now";
String line2Text = "There";
String line3Text = "Thisshire";
String line4Text = "GU66 74S";
String phoneText = "Phone: 010101 0101010";
String mobileText = "Mobile: 010101 010101";
String emailText = "Email: here#there.com";
//to/for strings
String toString = "To: " + pupilName[pupCount-1];
String forString = "For: " + parentsName[parCount-1];
//footer strings
String footerLine1 = "Please pay by cash or cheque made payable to " + " " + " or by Internet Banking.";
String footerBold1 = "Mrs Bob Bobbins";
String iBankingDet = "company Sort code: " + " " + " Account Number: " + " " + "put your name as";
String bSortCode = "00-00-00";
String bAccountNumber = "0000000";
String iBankingDet2 = "reference!";
String noticeAlert = "Please Pay by latest on the first lesson of Term/Series.";
String customNotice = "** Thank you for your custom **";
//Set fonts
Font textFont = new Font("Tahoma", Font.PLAIN, 10);
Font toForFont = new Font("Tahoma", Font.BOLD, 10);
Font addressFont = new Font("Tahoma", Font.PLAIN, 8);
Font titleFont = new Font("Tahoma", Font.BOLD, 24);
Font textFontBold = new Font("Tahoma", Font.BOLD, 10);
//set table titles
g2d.setPaint(Color.GRAY);
g2d.setFont(addressFont);
g2d.drawString(descrp, 15, 215);
g2d.drawString(sesh, 215, 215);
g2d.drawString(rate, 275, 215);
g2d.drawString(amount, 345, 215);
g2d.drawString(totalAmountString, 285, 495);
//set title
g2d.setFont(titleFont);
g2d.drawString(titleText, 250, 20);
//set address
g2d.setFont(addressFont);
g2d.drawString(line1Text, 350, 40);
g2d.drawString(line2Text, 350, 50);
g2d.drawString(line3Text, 350, 60);
g2d.drawString(line4Text, 350, 70);
g2d.drawString(phoneText, 350, 80);
g2d.drawString(mobileText, 350, 90);
g2d.drawString(emailText, 350, 100);
g2d.drawString(printDate, 350, 120);
//draw to and for strings
g2d.setPaint(Color.darkGray);
g2d.setFont(toForFont);
g2d.drawString(toString, 10, 160);
g2d.drawString(forString, 180, 160);
//draw footer onto page
g2d.setPaint(Color.black);
g2d.setFont(textFont);
g2d.drawString(footerLine1, 10, 520);
g2d.setFont(textFontBold);
g2d.drawString(footerBold1, 220, 520);
g2d.setFont(textFont);
g2d.drawString(iBankingDet, 10, 545);
g2d.setFont(textFontBold);
g2d.drawString(bSortCode, 165, 545);
g2d.drawString(bAccountNumber, 295, 545);
g2d.setFont(textFont);
g2d.drawString(iBankingDet2, 10, 555);
g2d.setFont(textFontBold);
g2d.drawString(noticeAlert, 95, 575);
g2d.drawString(customNotice, 145, 595);
//add image to invoice
Image img;
img = new ImageIcon(this.getClass().getResource("logo.png")).getImage();
g2d.drawImage(img, -10, -10, 180, 84, null);
return (PAGE_EXISTS);
}
}
So basically, all i need to do is pass additional parameters to the print method, but this is impossible! It wouldn't implement the print class other wise!
I've tried substituting arrays and a lot more, i can't think of anything else!
You can't add arguments to the print() as it must implement the interface.
However you can add any number of arguments to the constructor, and these can be used in your method.
bk.append(new IntroPage(arg1, arg2, arg3), PJ.defaultPage());
You could add fields to the class IntroPage. Then when you create IntroPage pass appropriate arguments to initialize your fileds. And later, in print(), you can use the data from your fileds.
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 have wrote program in java the program is to convert from KM to miles and miles to KM the program works fine but the problem is in the result in text area exceeded the area so does not appear the full text below the code attached. so i want if it is reached at the end of line it goes to new line
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
public class Converter extends JFrame implements ActionListener {
JLabel label = new JLabel("Distance : ");
JTextField input = new JTextField(10);
JButton button = new JButton("Convert");
JTextArea output = new JTextArea(10,15);
CheckboxGroup cbg = new CheckboxGroup();
Checkbox cb1 = new Checkbox("Convert MILES to KM", cbg, true);
Checkbox cb2 = new Checkbox("Convert KM to MILES", cbg, false);
public static void main(String args[]) {
Converter s = new Converter();
s.setVisible(true);
}
public Converter() {
setLayout(null);
setSize(300,400);
//left-down-width-hegiht
cb1.setBounds(60,30,150,30);
cb2.setBounds(60,60,150,30);
label.setBounds(30,90,120,30);
input.setBounds(90,95,170,20);
button.setBounds(100,130,90,30);
output.setBounds(45,168,200,165);
add(cb1);
add(cb2);
add(label);
add(input);
add(button);
add(output);
button.addActionListener(this);
}
public void actionPerformed(ActionEvent e) {
if (cb1.getState() ) {
if (e.getSource() == button) {
double d = Double.parseDouble(input.getText());
double d2 = d / 0.62;
String str2 = String.valueOf(d2);
output.setText(d + "miles equals to " + str2 + " kilometers");
}
}
if (cb2.getState()) {
if (e.getSource() == button){
double d = Double.parseDouble(input.getText());
double d2 = d * 0.62;
String str2 = String.valueOf(d2);
output.setText(d + " kilometers equals to " + str2 + " miles ");
}
}
}
}
If your goal is purely to have line wrapping on in the text area then you can make use of JTextArea's built-in function named setLineWrap.
Passing a true boolean value as a parameter to setLineWrap such as setLineWrap(true) will turn on line wrapping for the JTextArea component. Passing a false boolean value as a parameter will turn off line wrapping
In your code, it would be used as follows.
output.setLineWrap(true);
The Converter constructor will then look as follows.
public Converter() {
// Turn on line wrapping.
output.setLineWrap(true);
setLayout(null);
setSize(300, 400);
// left-down-width-hegiht
cb1.setBounds(60, 30, 150, 30);
cb2.setBounds(60, 60, 150, 30);
label.setBounds(30, 90, 120, 30);
input.setBounds(90, 95, 170, 20);
button.setBounds(100, 130, 90, 30);
output.setBounds(45, 168, 200, 165);
add(cb1);
add(cb2);
add(label);
add(input);
add(button);
add(output);
button.addActionListener(this);
}
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 this string: "This is my very long String that wont fit on one line"
And I need to split it into multiple lines so it'll fit where I need it.
Lets say theres only room for about 15 letters per line, then it should look like this:
"This is my very"
"long String"
"that wont fit"
"on one line"
I would like to split it into a List<String> so I can do
for(String s : lines) draw(s,x,y);
Any help on how to do this would be appriciated!
The way I'm rendering the text is with Graphics.drawString()
This is what I've tried so far (horrible, I know)
String diaText = "This is my very long String that wont fit on one line";
String[] txt = diaText.trim().split(" ");
int max = 23;
List<String> lines = new ArrayList<String>();
String s1 = "";
if (!(diaText.length() > max)) {
lines.add(diaText);
} else {
for (int i = 0; i < txt.length; i++) {
String ns = s1 += txt[i] + " ";
if (ns.length() < 23) {
lines.add(s1);
s1 = "";
} else {
s1 += txt[i] + "";
}
}
}
int yo = 0;
for (String s : lines) {
Font.draw(s, screen, 70, 15 + yo, Color.get(-1, 555, 555,555));
yo += 10;
}
import java.awt.*;
import java.awt.image.BufferedImage;
import javax.swing.*;
public class LabelRenderTest {
public static void main(String[] args) {
SwingUtilities.invokeLater( new Runnable() {
public void run() {
String title = "<html><body style='width: 200px; padding: 5px;'>"
+ "<h1>Do U C Me?</h1>"
+ "Here is a long string that will wrap. "
+ "The effect we want is a multi-line label.";
JFrame f = new JFrame("Label Render Test");
f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
BufferedImage image = new BufferedImage(
400,
300,
BufferedImage.TYPE_INT_RGB);
Graphics2D imageGraphics = image.createGraphics();
GradientPaint gp = new GradientPaint(
20f,
20f,
Color.red,
380f,
280f,
Color.orange);
imageGraphics.setPaint(gp);
imageGraphics.fillRect(0, 0, 400, 300);
JLabel textLabel = new JLabel(title);
textLabel.setSize(textLabel.getPreferredSize());
Dimension d = textLabel.getPreferredSize();
BufferedImage bi = new BufferedImage(
d.width,
d.height,
BufferedImage.TYPE_INT_ARGB);
Graphics g = bi.createGraphics();
g.setColor(new Color(255, 255, 255, 128));
g.fillRoundRect(
0,
0,
bi.getWidth(f),
bi.getHeight(f),
15,
10);
g.setColor(Color.black);
textLabel.paint(g);
Graphics g2 = image.getGraphics();
g2.drawImage(bi, 20, 20, f);
ImageIcon ii = new ImageIcon(image);
JLabel imageLabel = new JLabel(ii);
f.getContentPane().add(imageLabel);
f.pack();
f.setLocationByPlatform(true);
f.setVisible(true);
}
});
}
}
You could consider using LineBreakMeasurer which is intended for this sort of thing in a graphics environment. Please check out the JavaDocs here, which contain a couple of detailed examples on how to use it.
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.