Question:
Help java question exercise. 10 points if you are able to help?
2006-08-08 01:01:38 UTC
b)Create a window-based (swing) application named SumIntegers that allows the user to enter two integers into two separate TextFields. When the user clicks a Button, the integer is doubled and the answer is displayed.

c) c)Answer the following:
i.What Swing class is used to define a window?[2m]
ii.What units of measure are used in setSize(300,200) method?[1m]
iii.What is the method call to set the close-window button of the JFrame window so that the program ends when the user clicks the on the close window button.[2m]
iv.What kind of event is fired when you click the JButton event?[1m]
Three answers:
Dr.Mr.Ed
2006-08-08 05:35:20 UTC
Sorry to say this, but Eclipse probably isn't the best way to learn Java programming. Using SWT to answer these questions about Swing isn't all that helpful.



In reality, there's about 5 minutes of looking through the standard Swing tutorial to answer all of question (c). And maybe 5 minutes of code to write to answer question (b).



If you're having trouble finding online resources to answer these questions, you may want to rethink the reason why you're taking a Java class.
~FriEnD~
2006-08-08 08:49:59 UTC
important : only compile in eclipse... (coz i use eclipse library)





import org.eclipse.swt.SWT;

import org.eclipse.swt.browser.Browser;

import org.eclipse.swt.custom.CCombo;

import org.eclipse.swt.custom.CLabel;

import org.eclipse.swt.custom.StyledText;

import org.eclipse.swt.events.MouseAdapter;

import org.eclipse.swt.events.MouseEvent;

import org.eclipse.swt.graphics.Font;

import org.eclipse.swt.graphics.Point;

import org.eclipse.swt.graphics.Rectangle;

import org.eclipse.swt.widgets.Button;

import org.eclipse.swt.widgets.Combo;

import org.eclipse.swt.widgets.Display;

import org.eclipse.swt.widgets.Label;

import org.eclipse.swt.widgets.Link;

import org.eclipse.swt.widgets.List;

import org.eclipse.swt.widgets.Menu;

import org.eclipse.swt.widgets.ProgressBar;

import org.eclipse.swt.widgets.Scale;

import org.eclipse.swt.widgets.Shell;

import org.eclipse.swt.widgets.Slider;

import org.eclipse.swt.widgets.Spinner;

import org.eclipse.swt.widgets.Table;

import org.eclipse.swt.widgets.TableColumn;

import org.eclipse.swt.widgets.TableItem;

import org.eclipse.swt.widgets.Text;

import org.eclipse.swt.widgets.ToolBar;

import org.eclipse.swt.widgets.Tree;

import org.eclipse.swt.widgets.TreeColumn;



public class myve {



private Shell sShell = null; // @jve:decl-index=0:visual-constraint="10,0"

private Text sop1 = null;

private Text sop2 = null;

private Button b_tambah = null;

private Text shasil = null;

private Button b_kali = null;

private Button b_bagi = null;

private Button checkBox = null;

private Button radioButton = null;

private Button radioButton1 = null;

private Menu menuBar = null;

private Label mylabel = null;

private CLabel cLabel = null;

private Link link = null;

private Text textArea = null;

private StyledText styledText = null;

private List list = null;

private Combo combo = null;

private CCombo cCombo = null;

private ProgressBar progressBar = null;

private Spinner spinner = null;

private Slider slider = null;

private Scale scale = null;

private Table table = null;

private Tree tree = null;

private ToolBar toolBar = null;

private Browser browser = null;

/**

* This method initializes combo

*

*/

private void createCombo() {

combo = new Combo(sShell, SWT.NONE);

combo.setItems(new String[] {"string satu","String dua","String tiga"});

combo.select(0);

combo.setBounds(new Rectangle(172, 348, 87, 90));

}



/**

* This method initializes toolBar

*

*/

private void createToolBar() {

toolBar = new ToolBar(sShell, SWT.NONE);

toolBar.setBounds(new Rectangle(595, 407, 142, 57));

}



/**

* This method initializes browser

*

*/

private void createBrowser() {

browser = new Browser(sShell, SWT.NONE);

browser.setBounds(new Rectangle(575, 7, 166, 204));

}



/**

* @param args

*/

public static void main(String[] args) {

// TODO Auto-generated method stub

/* Before this is run, be sure to set up the launch configuration (Arguments->VM Arguments)

* for the correct SWT library path in order to run with the SWT dlls.

* The dlls are located in the SWT plugin jar.

* For example, on Windows the Eclipse SWT 3.1 plugin jar is:

* installation_directory\plugins\org.eclipse.swt.win32_3.1.0.jar

*/

Display display = Display.getDefault();

myve thisClass = new myve();

thisClass.createSShell();

thisClass.sShell.open();



while (!thisClass.sShell.isDisposed()) {

if (!display.readAndDispatch())

display.sleep();

}

display.dispose();

}



/**

* This method initializes sShell

*/

private void createSShell() {

sShell = new Shell();

sShell.setText("My first Window using Eclipse");

sShell.setSize(new Point(755, 508));

sShell.setLayout(null);

menuBar = new Menu(sShell, SWT.BAR);

sShell.setMenuBar(menuBar);

sop1 = new Text(sShell, SWT.BORDER);

sop1.setBounds(new Rectangle(96, 18, 76, 19));

sop2 = new Text(sShell, SWT.BORDER);

sop2.setBounds(new Rectangle(96, 48, 76, 19));

b_tambah = new Button(sShell, SWT.NONE);

b_tambah.setBounds(new Rectangle(207, 18, 59, 23));

b_tambah.setText("tambah");

b_tambah.addSelectionListener(new org.eclipse.swt.events.SelectionAdapter() {

public void widgetSelected(org.eclipse.swt.events.SelectionEvent e) {

System.out.println("widgetSelected()"); // TODO Auto-generated Event stub widgetSelected()

shasil.setText( String.valueOf(Integer.parseInt(sop1.getText()) + Integer.parseInt(sop2.getText())) );

}

});

shasil = new Text(sShell, SWT.BORDER);

shasil.setBounds(new Rectangle(96, 92, 76, 19));

shasil.setEnabled(false);

b_kali = new Button(sShell, SWT.NONE);

b_kali.setBounds(new Rectangle(207, 49, 59, 23));

b_kali.setText("kali");

b_kali.addSelectionListener(new org.eclipse.swt.events.SelectionAdapter() {

public void widgetSelected(org.eclipse.swt.events.SelectionEvent e) {

System.out.println("widgetSelected()"); // TODO Auto-generated Event stub widgetSelected()

shasil.setText( String.valueOf(Integer.parseInt(sop1.getText()) * Integer.parseInt(sop2.getText())) );

}

});

b_bagi = new Button(sShell, SWT.NONE);

b_bagi.setBounds(new Rectangle(207, 85, 59, 23));

b_bagi.setText("bagi");

checkBox = new Button(sShell, SWT.CHECK);

checkBox.setBounds(new Rectangle(285, 15, 85, 29));

checkBox.setText("chek satu");

radioButton = new Button(sShell, SWT.RADIO);

radioButton.setBounds(new Rectangle(283, 64, 78, 22));

radioButton.setSelection(true);

radioButton.setText("radio satu");

radioButton1 = new Button(sShell, SWT.RADIO);

radioButton1.setBounds(new Rectangle(283, 91, 69, 16));

radioButton1.setText("radio dua");

mylabel = new Label(sShell, SWT.NONE);

mylabel.setBounds(new Rectangle(17, 20, 65, 20));

mylabel.setText("operator 1");

cLabel = new CLabel(sShell, SWT.NONE);

cLabel.setText("CLabel");

cLabel.setToolTipText("ok ok ini tooltip clabel");

cLabel.setBounds(new Rectangle(17, 51, 67, 34));

link = new Link(sShell, SWT.NONE);

link.setBounds(new Rectangle(8, 441, 106, 24));

link.setToolTipText("in link ke email google");

link.setText("mail.google.com");

textArea = new Text(sShell, SWT.MULTI | SWT.WRAP | SWT.V_SCROLL);

textArea.setBounds(new Rectangle(14, 124, 360, 178));

styledText = new StyledText(sShell, SWT.NONE);

styledText.setText("Ini styled text");

styledText.setFont(new Font(Display.getDefault(), "Comic Sans MS", 10, SWT.NORMAL));

styledText.setBackground(Display.getCurrent().getSystemColor(SWT.COLOR_WIDGET_BACKGROUND));

styledText.setBounds(new Rectangle(13, 314, 362, 25));

list = new List(sShell, SWT.SINGLE | SWT.BORDER);

list.setItems(new String[] {"satu","dua","tiga","empat","lima","enam",

"tujuh","delapan","sembilan","sepuluh"});

list.setBounds(new Rectangle(13, 348, 153, 89));

createCombo();

cCombo = new CCombo(sShell, SWT.NONE);

cCombo.setBounds(new Rectangle(172, 375, 210, 64));

progressBar = new ProgressBar(sShell, SWT.NONE);

progressBar.setBounds(new Rectangle(120, 442, 262, 24));

spinner = new Spinner(sShell, SWT.NONE);

spinner.setBounds(new Rectangle(396, 14, 100, 25));

slider = new Slider(sShell, SWT.NONE);

slider.setBounds(new Rectangle(397, 57, 167, 100));

scale = new Scale(sShell, SWT.NONE);

scale.setBounds(new Rectangle(394, 163, 160, 46));



// create table

table = new Table(sShell, SWT.NONE);

table.setHeaderVisible(true);

table.setLinesVisible(true);

table.setBounds(new Rectangle(396, 218, 100, 117));

// create column

TableColumn first = new TableColumn(table,SWT.LEFT);

first.setWidth(50);

first.setResizable(true);

first.setText("First");

TableColumn second = new TableColumn(table,SWT.LEFT);

second.setWidth(50);

second.setResizable(true);

second.setText("Second");

// insert

TableItem[] item = new TableItem[1];

item[0] = new TableItem(table,SWT.NONE);

item[0].setText(new String[] {"Anjar","Bandung"});

item = new TableItem[2];

item[1] = new TableItem(table,SWT.NONE);

item[1].setText(new String[] {"Indira","Bandung"});

//item[item.length] = new TableItem(table,SWT.NONE);





tree = new Tree(sShell, SWT.NONE);

tree.setHeaderVisible(true);

tree.setLinesVisible(true);

tree.setBounds(new Rectangle(394, 341, 192, 124));

createToolBar();

createBrowser();

TreeColumn treeColumn = new TreeColumn(tree, SWT.NONE);

treeColumn.setWidth(60);

b_bagi.addSelectionListener(new org.eclipse.swt.events.SelectionAdapter() {

public void widgetSelected(org.eclipse.swt.events.SelectionEvent e) {

System.out.println("widgetSelected()"); // TODO Auto-generated Event stub widgetSelected()

shasil.setText( String.valueOf(Integer.parseInt(sop1.getText()) / Integer.parseInt(sop2.getText())) );

}

});

list.addMouseListener(new MouseAdapter() {

public void mouseDown(MouseEvent e) {

System.out.println(list.getSelection()[0] +" wins");

}

public void mouseUp(MouseEvent e) {

System.out.println("Try again!");

}

});

}



}



c) u can see my code before u ask me point c question.
Matthew
2006-08-08 08:06:51 UTC
I really dont know but i want the 10 PTS SOOO BAD, lol sorry


This content was originally posted on Y! Answers, a Q&A website that shut down in 2021.
Loading...