java窗体实例代码 java 窗体开发

急求JAVA简易计算器窗体设计代码

窗体写好了,运算你自己写

创新互联成立以来不断整合自身及行业资源、不断突破观念以使企业策略得到完善和成熟,建立了一套“以技术为基点,以客户需求中心、市场为导向”的快速反应体系。对公司的主营项目,如中高端企业网站企划 / 设计、行业 / 企业门户设计推广、行业门户平台运营、app软件开发、手机网站开发、微信网站制作、软件开发、西信服务器托管等实行标准化操作,让客户可以直观的预知到从创新互联可以获得的服务效果。

import java.awt.Button;

import java.awt.GridLayout;

import javax.swing.JFrame;

import javax.swing.JLabel;

import javax.swing.JPanel;

import javax.swing.JTextField;

public class SimpleCalculator {

private JFrame f = new JFrame();

private JPanel firstPanel = new JPanel();

private JLabel firstNumLabel = new JLabel("第一个数字");

private JTextField number1 = new JTextField();

private JPanel secondPanel = new JPanel();

private Button add = new Button("+");

private Button mul = new Button("*");

private Button clear = new Button("清除");

private JPanel thirdPanel = new JPanel();

private JLabel resultLabel = new JLabel("结果为");

private JTextField result = new JTextField();

public SimpleCalculator(){

firstPanel.setLayout(new GridLayout(1, 2));

firstPanel.add(firstNumLabel);

firstPanel.add(number1);

secondPanel.setLayout(new GridLayout(1, 3));

secondPanel.add(add);

secondPanel.add(mul);

secondPanel.add(clear);

thirdPanel.setLayout(new GridLayout(1, 2));

thirdPanel.add(resultLabel);

thirdPanel.add(result);

f.add(new JLabel("简易计算器"));

f.add(firstPanel);

f.add(secondPanel);

f.add(thirdPanel);

f.setLayout(new GridLayout(4, 1));

f.setVisible(true);

f.pack();

f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

}

public static void main(String[] args) {

new SimpleCalculator();

}

}

急求Java窗体设计代码?我会追加分的

计算器:import java.awt.*;

import java.awt.event.*;

import java.awt.BorderLayout;

import javax.swing.JPanel;

import javax.swing.JFrame;

import java.awt.TextField;

import java.awt.Rectangle;

import java.awt.Button;

import java.awt.Label;public class suanfa extends JFrame {private static final long serialVersionUID = 1L;private JPanel jContentPane = null;private TextField textField = null;private TextField textField1 = null;private Button button = null;private Button button1 = null;private Button button2 = null;private Button button3 = null;private Label label = null;

double awn;

/**

* This is the default constructor

*/

public suanfa() {

super();

initialize();

}/**

* This method initializes this

*

* @return void

*/

private void initialize() {

this.setSize(300, 250);

this.setContentPane(getJContentPane());

this.setTitle("JFrame");

}/**

* This method initializes jContentPane

*

* @return javax.swing.JPanel

*/

private JPanel getJContentPane() {

if (jContentPane == null) {

label = new Label();

label.setBounds(new Rectangle(12, 129, 90, 27));

label.setText(String.format("%.6f",awn));

jContentPane = new JPanel();

jContentPane.setLayout(null);

jContentPane.add(getTextField(), null);

jContentPane.add(getTextField1(), null);

jContentPane.add(getButton(), null);

jContentPane.add(getButton1(), null);

jContentPane.add(getButton2(), null);

jContentPane.add(getButton3(), null);

jContentPane.add(label, null);

}

return jContentPane;

}/**

* This method initializes textField

*

* @return java.awt.TextField

*/

private TextField getTextField() {

if (textField == null) {

textField = new TextField();

textField.setBounds(new Rectangle(11, 20, 75, 32));

}

return textField;

}/**

* This method initializes textField1

*

* @return java.awt.TextField

*/

private TextField getTextField1() {

if (textField1 == null) {

textField1 = new TextField();

textField1.setBounds(new Rectangle(11, 67, 75, 32));

}

return textField1;

}/**

* This method initializes button

*

* @return java.awt.Button

*/

private Button getButton() {

if (button == null) {

button = new Button("加");

button.setBounds(new Rectangle(134, 17, 71, 29));

button.addActionListener(new java.awt.event.ActionListener() {

public void actionPerformed(java.awt.event.ActionEvent e) {

try{

awn=Double.valueOf(textField.getText()) + Double.valueOf(textField1.getText());

label.setText(String.format("%.6f",awn));

}

catch(Exception ex){

return;

}

}

});

}

return button;

}/**

* This method initializes button1

*

* @return java.awt.Button

*/

private Button getButton1() {

if (button1 == null) {

button1 = new Button("减");

button1.setBounds(new Rectangle(134, 52, 71, 29));

button1.addActionListener(new java.awt.event.ActionListener() {

public void actionPerformed(java.awt.event.ActionEvent e) {

try{

awn=Double.valueOf(textField.getText()) - Double.valueOf(textField1.getText());

label.setText(String.format("%.6f",awn));

}

catch(Exception ex){

return;

}}

});

}

return button1;

}/**

* This method initializes button2

*

* @return java.awt.Button

*/

private Button getButton2() {

if (button2 == null) {

button2 = new Button("乘");

button2.setBounds(new Rectangle(134, 91, 71, 29));

button2.addActionListener(new java.awt.event.ActionListener() {

public void actionPerformed(java.awt.event.ActionEvent e) {

try{

awn=Double.valueOf(textField.getText()) * Double.valueOf(textField1.getText());

label.setText(String.format("%.6f",awn));

}

catch(Exception ex){

return;

}}

});

}

return button2;

}/**

* This method initializes button3

*

* @return java.awt.Button

*/

private Button getButton3() {

if (button3 == null) {

button3 = new Button("除");

button3.setBounds(new Rectangle(134, 133, 71, 29));

button3.addActionListener(new java.awt.event.ActionListener() {

public void actionPerformed(java.awt.event.ActionEvent e) {

try{

awn=Double.valueOf(textField.getText()) / Double.valueOf(textField1.getText());

label.setText(String.format("%.6f",awn));

}

catch(Exception ex){

return;

}}

});

}

return button3;

}

public static void main(String[] args)

{

new suanfa().setVisible(true);

}

}

求Java窗体代码,可显示文本.

importjava.awt.event.ActionEvent;importjava.awt.event.ActionListener;importjava.awt.event.KeyEvent;importjava.awt.event.KeyListener;importjavax.swing.JButton;importjavax.swing.JEditorPane;importjavax.swing.JFrame;importjavax.swing.JLabel;importjavax.swing.JPanel;importjavax.swing.JTextField;publicclassWindowTestextendsJFrameimplementsActionListener,KeyListener{privatestaticfinallongserialVersionUID=1L;/***主方法*/publicstaticvoidmain(String[]args){WindowTestwin=newWindowTest();}/***下面是具体实现*/JTextFieldtext;JButtonbutton;JEditorPanetextArea;publicWindowTest(){super("测试窗体");text=newJTextField(15);text.addKeyListener(this);JPanelp1=newJPanel();p1.add(newJLabel("输入字符:"));p1.add(text);button=newJButton("清除");button.addActionListener(this);p1.add(button);p1.setBounds(5,5,220,100);textArea=newJEditorPane();textArea.setBounds(1,1,216,200);JPanelp2=newJPanel();p2.add(newJLabel("显示字符:"));p2.add(textArea);p2.setBounds(5,115,340,220);JPanelp3=newJPanel();p3.add(p1);p3.add(p2);add(p3);setBounds(160,60,400,300);setVisible(true);setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);}@OverridepublicvoidkeyPressed(KeyEvente){}@OverridepublicvoidkeyReleased(KeyEvente){if(e.getKeyCode()==KeyEvent.VK_ENTER){textArea.setText("");}else{Stringstr=text.getText();textArea.setText(str);}}@OverridepublicvoidkeyTyped(KeyEvente){}@OverridepublicvoidactionPerformed(ActionEvente){text.setText("");textArea.setText("");}}

用java写一个窗口

import java.awt.BorderLayout;

import java.awt.Toolkit;

import javax.swing.JButton;

import javax.swing.JFrame;

import javax.swing.JLabel;

import javax.swing.JPanel;

import javax.swing.JTextField;

public class MyFrame extends JFrame {

private JLabel lab_name;

private JLabel lab_number;

private JLabel lab_amount;

private JTextField jtf_name;

private JTextField jtf_number;

private JTextField jtf_amount;

private JButton but_1;

private JButton but_2;

private JButton but_3;

public MyFrame(){

setSize(245, 260);

setTitle("JLabel Demo");

Toolkit tk = Toolkit.getDefaultToolkit();

setLocation((tk.getScreenSize().height - this.HEIGHT)/2,

(tk.getScreenSize().width - this.WIDTH)/2);

this.setLayout(null);

lab_name = new JLabel("姓名");

lab_number = new JLabel("学号");

lab_amount = new JLabel("金额");

jtf_name = new JTextField(13);

jtf_number = new JTextField(13);

jtf_amount = new JTextField(13);

JPanel jp_top = new JPanel();

jp_top.setBounds(0, 20, 245, 100);

jp_top.setLayout(new BorderLayout());

JPanel jp_top_name = new JPanel();

JPanel jp_top_number = new JPanel();

JPanel jp_top_amount = new JPanel();

jp_top_name.add(lab_name);

jp_top_name.add(jtf_name);

jp_top_number.add(lab_number);

jp_top_number.add(jtf_number);

jp_top_amount.add(lab_amount);

jp_top_amount.add(jtf_amount);

jp_top.add(jp_top_name,BorderLayout.NORTH);

jp_top.add(jp_top_number,BorderLayout.CENTER);

jp_top.add(jp_top_amount,BorderLayout.SOUTH);

JPanel jp_bottom = new JPanel();

jp_bottom.setBounds(0,150, 245, 90);

but_1 = new JButton("提交");

but_2 = new JButton("取消");

but_3 = new JButton("重写");

jp_bottom.add(but_1);

jp_bottom.add(but_2);

jp_bottom.add(but_3);

this.add(jp_top,BorderLayout.NORTH);

this.add(jp_bottom,BorderLayout.CENTER);

setVisible(true);

setResizable(false);

setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

}

public static void main(String[] args) {

new MyFrame();

}

}

LZ看下合适不。。。按钮想要美化的话 到网上再搜下。。。美化我不在行。。。


当前标题:java窗体实例代码 java 窗体开发
URL标题:http://azwzsj.com/article/hieeei.html