ABOVE IS THE SOLUTION OF THE QUESTION ASKED BEFORE BUT WAS NOT ANSWERED, SO I NE
ID: 3539750 • Letter: A
Question
ABOVE IS THE SOLUTION OF THE QUESTION ASKED BEFORE BUT WAS NOT ANSWERED, SO I NEED HELP WHEN I COMPILE WORKS WELL BUT I TRY TO EXCUTE IT TELLS ME THAT T NEEDS THE MAIN. CAN YOU HELP ME TO EXCUTE THIS PROGRAM. THE QUESTION WAS THIS Create the GUI-Align. You doNt need to provide any functionality. THE QUESTION IS AVAILABLE IN ( exercise 14.8 of the 9th Edition textbook. NSBN 9780132575669 )
1.
book information
How to program
please test it and send me the out output with program.
IGNORE THE BELOW TABLE
Explanation / Answer
for Applets and JApplets no need of any main method.just add some html code at the beginning of program and use the following commands for compiling and running:
for compiling :
javac Align.java
for running:
appletviewer Align.java
Note: Dont use " java Align" for running.
Code after adding "HTML part" in beginning is:
import javax.swing.*;
import java.awt.*;
/*
<applet code="Align" width=500 height=500>
</applet>
*/
public class Align extends JApplet {
private JButton ok, cancel, help;
private JTextField xValue, yValue;
private JCheckBox snap, show;
private JLabel xLabel, yLabel;
private JPanel checkPanel, buttonPanel,
fieldPanel1, fieldPanel2,
fieldPanel;
public void init()
{
// build checkPanel
snap = new JCheckBox( "Snap to Grid" );
show = new JCheckBox( "Show Grid" );
checkPanel = new JPanel();
checkPanel.setLayout( new GridLayout( 2 , 1 ) );
checkPanel.add( snap );
checkPanel.add( show );
// build field panel1
xLabel = new JLabel( "X: " );
xValue = new JTextField( "8", 3 );
fieldPanel1 = new JPanel();
fieldPanel1.setLayout( new FlowLayout( FlowLayout.CENTER, 3, 5 ) );
fieldPanel1.add( xLabel );
fieldPanel1.add( xValue );
yLabel = new JLabel( "Y: " );
yValue = new JTextField( "8", 3 );
fieldPanel2 = new JPanel();
fieldPanel2.setLayout( new FlowLayout( FlowLayout.CENTER, 3, 5 ) );
fieldPanel2.add( yLabel );
fieldPanel2.add( yValue );
fieldPanel = new JPanel();
fieldPanel.setLayout( new BorderLayout() );
fieldPanel.add( fieldPanel1, BorderLayout.NORTH );
fieldPanel.add( fieldPanel2, BorderLayout.SOUTH );
// build button panel
ok = new JButton( "Ok" );
cancel = new JButton( "Cancel" );
help = new JButton( "Help" );
buttonPanel = new JPanel();
buttonPanel.setLayout( new GridLayout( 3, 1, 10, 5 ) );
buttonPanel.add( ok );
buttonPanel.add( cancel );
buttonPanel.add( help );
// set layout for applet
getContentPane().setLayout(
new FlowLayout( FlowLayout.CENTER, 10, 5 ) );
getContentPane().add( checkPanel );
getContentPane().add( fieldPanel );
getContentPane().add( buttonPanel );
}
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.