把JAVA的程序放到网站里

把JAVA的程序放到网站里,第1张

java文件是java的源文件,这个在使用时是不必要的。class文件相当于java的执行文件,这个是必须的。

把java类运用到网页中,我知道的基本有以下几种方式。

1如果你做的计时器是一个applet,有界面的,那么把这个class放到和你的html或者jsp文档同目录中,然后在需要引用改applet的地方写下如下代码:

<APPLET code="c1_2class" width=150 height=100></APPLET>

这个方式最简单。

2要引用java类程序,我觉得你应该是使用jsp页面吧~,如果是jsp页面,jsp中有<jsp:useBean/>方法,你要看一下,这个不是一两句话能说清楚的。里面可以设置模式为applet,也可以直接把你的java applet类引入页面。

3注意,毕竟java和jsp还是有区别的。如果要做什么特效,用javascript我觉得比较方便。用java做的gui界面除了applet能引入网页,其他的好像不能,至少我没见过。

class文件在jsp技术中叫做bean,所以jsp中所有和bean有关的技术都可以使用特定的class文件。比如java bean的useBean,用struts等框架,用ejb(一种特殊的bean)等等,还可以用servlet,servlet可以直接使用一种特定类型的class文件,不过要用servlet做界面,悬。

如果真想用java相关技术做网页的话,还是先学学jsp吧。这是最简单的。

楼上说的很详细了,我说几点。

AWT,摇摆用于开发图形用户界面。

关于这个applet(Java小程序主要是用来开发的程序在网络上)

在Java刚出生时,主要是用于开发applet程序,主要用于AWT 。

摆动的基础上开发的GUI工具包AWT的新概念设计。

现实的情况是:

1。小应用程序现在已经很少使用。

2。例如,摆动主要用于开发Java桌面应用程序,也离不开从开发的java桌面程序AWT,AWT事件里面的类将被频繁使用。

你可以不学的小程序,但你不能帮助,但学习AWT和Swing

// My car shopjava

import javaawt;

import javaawtevent;

import javaxswing;

import javaxswingborder;

public class carshop extends JFrame

{

// JPanel to hold all pictures

private JPanel windowJPanel;

private String[] cars = { "","阿斯顿马丁", "美洲虎", "凯迪拉克",

"罗孚", "劳斯莱斯","别克"};

private int[] jiage = { 0,150000, 260000, 230000,

140000, 290000, 150000};

// JLabels for first snack shown

private JLabel oneJLabel;

private JLabel oneIconJLabel;

// JLabels for second snack shown

private JLabel twoJLabel;

private JLabel twoIconJLabel;

// JLabels for third snack shown

private JLabel threeJLabel;

private JLabel threeIconJLabel;

// JLabels for fourth snack shown

private JLabel fourJLabel;

private JLabel fourIconJLabel;

// JLabels for fifth snack shown

private JLabel fiveJLabel;

private JLabel fiveIconJLabel;

// JLabels for sixth snack shown

private JLabel sixJLabel;

private JLabel sixIconJLabel;

// JTextField for displaying snack price

private JTextArea displayJTextArea;

// JLabel and JTextField for user input

private JLabel inputJLabel;

private JComboBox selectCountryJComboBox;

private JLabel inputJLabel2;

private JTextField inputJTextField2;

// JButton to enter user input

private JButton enterJButton;

//JButton to clear the components

private JButton clearJButton;

// no-argument constructor

public carshop()

{

createUserInterface();

}

// create and position GUI components; register event handlers

private void createUserInterface()

{

// get content pane for attaching GUI components

Container contentPane = getContentPane();

// enable explicit positioning of GUI components

contentPanesetLayout( null );

// set up windowJPanel

windowJPanel = new JPanel();

windowJPanelsetBounds( 10, 20, 340, 200 );

windowJPanelsetBorder( new LineBorder( ColorBLACK ) );

windowJPanelsetLayout( null );

contentPaneadd( windowJPanel );

// set up oneIconJLabel

oneIconJLabel = new JLabel();

oneIconJLabelsetBounds( 10, 20, 100, 65 );

oneIconJLabelsetIcon( new ImageIcon( "images/阿斯顿马丁jpg" ) );

windowJPaneladd( oneIconJLabel );

// set up oneJLabel

oneJLabel = new JLabel();

oneJLabelsetBounds( 10, 60, 100, 70 );

oneJLabelsetText( "阿斯顿马丁" );

oneJLabelsetHorizontalAlignment( JLabelCENTER );

windowJPaneladd( oneJLabel );

// set up twoIconJLabel

twoIconJLabel = new JLabel();

twoIconJLabelsetBounds( 120, 20, 100, 65 );

twoIconJLabelsetIcon( new ImageIcon( "images/美洲虎jpg" ) );

windowJPaneladd( twoIconJLabel );

// set up twoJLabel

twoJLabel = new JLabel();

twoJLabelsetBounds( 110, 60, 100, 70 );

twoJLabelsetText( "美洲虎" );

twoJLabelsetHorizontalAlignment( JLabelCENTER );

windowJPaneladd( twoJLabel );

// set up threeIconJLabel

threeIconJLabel = new JLabel();

threeIconJLabelsetBounds( 230, 20, 100, 65 );

threeIconJLabelsetIcon( new ImageIcon(

"images/凯迪拉克jpg" ) );

windowJPaneladd( threeIconJLabel );

// set up threeJLabel

threeJLabel = new JLabel();

threeJLabelsetBounds( 230, 60, 100, 70);

threeJLabelsetText( "凯迪拉克" );

threeJLabelsetHorizontalAlignment( JLabelCENTER );

windowJPaneladd( threeJLabel );

// set up fourIconJLabel

fourIconJLabel = new JLabel();

fourIconJLabelsetBounds( 10, 100, 100, 65 );

fourIconJLabelsetIcon( new ImageIcon( "images/罗孚jpg" ) );

windowJPaneladd( fourIconJLabel );

// set up fourJLabel

fourJLabel = new JLabel();

fourJLabelsetBounds( 10, 150, 50, 70 );

fourJLabelsetText( "罗孚" );

fourJLabelsetHorizontalAlignment( JLabelCENTER );

windowJPaneladd( fourJLabel );

// set up fiveIconJLabel

fiveIconJLabel = new JLabel();

fiveIconJLabelsetBounds( 120, 100, 100, 65 );

fiveIconJLabelsetIcon( new ImageIcon(

"images/劳斯莱斯jpg" ) );

windowJPaneladd( fiveIconJLabel );

// set up fiveJLabel

fiveJLabel = new JLabel();

fiveJLabelsetBounds( 110, 150, 100, 70 );

fiveJLabelsetText( "劳斯莱斯" );

fiveJLabelsetHorizontalAlignment( JLabelCENTER );

windowJPaneladd( fiveJLabel );

// set up sixIconJLabel

sixIconJLabel = new JLabel();

sixIconJLabelsetBounds( 230, 100, 100, 65 );

sixIconJLabelsetIcon( new ImageIcon( "images/别克jpg" ) );

windowJPaneladd( sixIconJLabel );

// set up sixJLabel

sixJLabel = new JLabel();

sixJLabelsetBounds( 230, 150, 100, 70 );

sixJLabelsetText( "别克" );

sixJLabelsetHorizontalAlignment( JLabelCENTER );

windowJPaneladd( sixJLabel );

// set up enterJButton

enterJButton = new JButton();

enterJButtonsetBounds( 390, 160, 135, 30 );

enterJButtonsetText( "Enter" );

contentPaneadd( enterJButton );

enterJButtonaddActionListener(

new ActionListener() // anonymous inner class

{

// event handler called when enterJButton is clicked

public void actionPerformed( ActionEvent event )

{

enterJButtonActionPerformed( event );

}

} // end anonymous inner class

); // end call to addActionListener

// set up clearJButton

clearJButton = new JButton();

clearJButtonsetBounds( 390, 200, 135, 30 );

clearJButtonsetText( "Clear" );

contentPaneadd( clearJButton );

// set up inputJLabel

inputJLabel = new JLabel();

inputJLabelsetBounds( 390, 25, 135, 25 );

inputJLabelsetText( "Please make selection:" );

contentPaneadd( inputJLabel );

selectCountryJComboBox = new JComboBox( cars );

selectCountryJComboBoxsetBounds( 390, 50, 135, 21 );

selectCountryJComboBoxsetMaximumRowCount( 3 );

contentPaneadd( selectCountryJComboBox );

// set up inputJTextField

inputJLabel2 = new JLabel();

inputJLabel2setBounds( 390, 80, 150, 20 );

inputJLabel2setText( "Input the Numble:" );

contentPaneadd( inputJLabel2 );

// set up inputJTextField

inputJTextField2 = new JTextField();

inputJTextField2setBounds( 390, 100, 135, 25 );

inputJTextField2setHorizontalAlignment( JTextFieldRIGHT );

contentPaneadd( inputJTextField2 );

clearJButtonaddActionListener(

new ActionListener() // anonymous inner class

{

// event handler called when clearJButton is clicked

public void actionPerformed( ActionEvent event )

{

clearJButtonActionPerformed( event );

}

} // end anonymous inner class

);

// set up displayJTextField

displayJTextArea = new JTextArea();

displayJTextAreasetBounds( 10, 237,515, 70 );

displayJTextAreasetEditable( false );

contentPaneadd( displayJTextArea );

// set properties of application's window

setTitle( "My car Shop" ); // set title bar string

setSize( 550, 360 ); // set window size

setVisible( true ); // display window

} // end method createUserInterface

private void clearJButtonActionPerformed( ActionEvent event )

{

// clear the JTextFields

inputJTextField2setText( "" );

displayJTextAreasetText("");

} // end method clearJButtonActionPerformed

private void enterJButtonActionPerformed( ActionEvent event )

{

double z;

double c;

int x;

int y;

x=selectCountryJComboBoxgetSelectedIndex();

y=IntegerparseInt(inputJTextField2getText());

double discountRate;

int amount = IntegerparseInt( inputJTextField2getText());

switch (amount/5)

{

case 0:

discountRate = 0;

break;

case 1:

discountRate = 1;

break;

case 2:

discountRate = 2;

break;

case 3:

discountRate = 3;

break;

default:

discountRate = 4;

} // end switch statement

c=1-discountRate/100;

z=jiage[x]yc;

displayJTextAreaappend("你选择的是:"+cars[x]+";"+

"它的单价是:"+jiage[x]+";" +"你购买该产品的数量是:"+y+"," +"\n"+"该数量的折扣是:"

+discountRate + " %"+";"+"本次消费的总价格是:"+z+"元"+"!"+"\n");

}

public static void main( String args[] )

{

carshop application = new carshop();

applicationsetDefaultCloseOperation( JFrameEXIT_ON_CLOSE );

} // end method main

} // end class carshop

以上就是关于把JAVA的程序放到网站里全部的内容,包括:把JAVA的程序放到网站里、哎,二级报的java,可是发现有好多applet和awt及swing的,applet我压根就没学,也不想学。、java小程序源代码,简单点的,100多行,谁有啊等相关内容解答,如果想了解更多相关内容,可以关注我们,你们的支持是我们更新的动力!

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/zz/9710928.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2023-05-01
下一篇 2023-05-01

发表评论

登录后才能评论

评论列表(0条)

保存