Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

help me run the code import org.eclipse.swt.SWT; import org.eclipse.swt.widgets.Display; import org.eclipse.swt.widgets.FileDialog; import org.eclipse.swt.widgets.Shell; import org.eclipse.swt.widgets.Label; import org.eclipse.swt.widgets.MessageBox; import org.eclipse.wb.swt.SWTResourceManager; import org.eclipse.swt.widgets.Text; import org.eclipse.swt.widgets.Tree; import org.eclipse.swt.widgets.Button;

help me run the code

import org.eclipse.swt.SWT; import org.eclipse.swt.widgets.Display; import org.eclipse.swt.widgets.FileDialog; import org.eclipse.swt.widgets.Shell; import org.eclipse.swt.widgets.Label; import org.eclipse.swt.widgets.MessageBox; import org.eclipse.wb.swt.SWTResourceManager; import org.eclipse.swt.widgets.Text; import org.eclipse.swt.widgets.Tree; import org.eclipse.swt.widgets.Button; import org.eclipse.swt.events.MouseAdapter; import org.eclipse.swt.events.MouseEvent; import org.eclipse.swt.widgets.Composite;

public class GUI { static String inputDataFileName; static double trainingDataSize; private static Text trainingDataPercentage; private static Label modelAccuracyLabel;

public GUI() { inputDataFileName = ""; trainingDataSize = 0.0; } /** * Launch the application. * @param args */ public static void main(String[] args) { GUI d = new GUI(); Display display = Display.getDefault(); Shell shell = new Shell(display, SWT.CLOSE); shell.setModified(false); shell.setSize(450, 300); shell.setText("SWT Application"); Label lblNewLabel = new Label(shell, SWT.NONE); lblNewLabel.setAlignment(SWT.CENTER); lblNewLabel.setFont(SWTResourceManager.getFont("Segoe UI", 20, SWT.BOLD)); lblNewLabel.setBounds(89, 10, 274, 44); lblNewLabel.setText("Simple Decision Tree"); Label lblOfData = new Label(shell, SWT.NONE); lblOfData.setFont(SWTResourceManager.getFont("Segoe UI", 14, SWT.NORMAL)); lblOfData.setBounds(10, 125, 187, 25); lblOfData.setText("% of data for training"); trainingDataPercentage = new Text(shell, SWT.BORDER); trainingDataPercentage.setBounds(203, 130, 59, 21); Label lblNewLabel_1 = new Label(shell, SWT.NONE); lblNewLabel_1.setFont(SWTResourceManager.getFont("Segoe UI", 12, SWT.NORMAL)); lblNewLabel_1.setBounds(268, 128, 55, 21); lblNewLabel_1.setText("%");

Button DataFileSelectorButton = new Button(shell, SWT.NONE); DataFileSelectorButton.addMouseListener(new MouseAdapter() { @Override public void mouseDown(MouseEvent e) { FileDialog dialog = new FileDialog(shell, SWT.OPEN); dialog.setFilterExtensions(new String [] {"*.*"}); dialog.setFilterPath("c:\\temp"); inputDataFileName = dialog.open(); } }); DataFileSelectorButton.setFont(SWTResourceManager.getFont("Segoe UI", 16, SWT.NORMAL)); DataFileSelectorButton.setBounds(10, 63, 117, 35); DataFileSelectorButton.setText("Data File..."); modelAccuracyLabel = new Label(shell, SWT.NONE); modelAccuracyLabel.setFont(SWTResourceManager.getFont("Segoe UI", 17, SWT.BOLD)); modelAccuracyLabel.setAlignment(SWT.CENTER); modelAccuracyLabel.setBounds(89, 220, 274, 31); Button btnBuildTree = new Button(shell, SWT.NONE); btnBuildTree.addMouseListener(new MouseAdapter() { @Override public void mouseDown(MouseEvent e) { try{ trainingDataSize = Double.parseDouble(trainingDataPercentage.getText()); if(inputDataFileName.equals("") || trainingDataSize == 0.0){ MessageBox emptyValueMessage = new MessageBox(shell,SWT.ICON_ERROR); emptyValueMessage.setMessage("Please provide all inputs to build a decision tree!"); emptyValueMessage.setText("Empty values Error"); emptyValueMessage.open(); } else if(trainingDataSize > 100){ throw new Exception("Give Percentage value less than or equal to 100!"); } else{ Driver driver = new Driver(trainingDataSize,inputDataFileName); String modelAccuracy = String.valueOf(driver.startTree()); String accuracyMessage = "Model Accuracy : " + modelAccuracy + "%"; System.out.println(accuracyMessage); modelAccuracyLabel.setText(accuracyMessage); } } catch(NumberFormatException numException){ MessageBox emptyValueMessage = new MessageBox(shell,SWT.ICON_ERROR); emptyValueMessage.setMessage("Please provide double or integer value in the percentage section!"); emptyValueMessage.setText("Datatype Mismatch Error"); emptyValueMessage.open(); } catch(Exception typeMismatch){ MessageBox emptyValueMessage = new MessageBox(shell,SWT.ICON_ERROR); emptyValueMessage.setMessage(typeMismatch.getMessage()); emptyValueMessage.setText("Datatype Mismatch Error"); emptyValueMessage.open(); } } }); btnBuildTree.setFont(SWTResourceManager.getFont("Segoe UI", 12, SWT.NORMAL)); btnBuildTree.setBounds(171, 172, 75, 25); btnBuildTree.setText("Build Tree"); shell.open(); shell.layout(); while (!shell.isDisposed()) { if (!display.readAndDispatch()) { display.sleep(); } } } }

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

More Books

Students also viewed these Databases questions