JAVA编程:编写一个图形界面的Application程序

怎样用java编写图形界面的Application程序?~

java编写图形界面需要用到swing等组件,可以在eclipse中安装windowbuilder来开发窗体,自动生成窗体代码,然后自己再根据需要修改,如:
package mainFrame;
import java.awt.EventQueue;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JCheckBox;
import javax.swing.JFrame。
Java是一门面向对象编程语言,不仅吸收了C++语言的各种优点,还摒弃了C++里难以理解的多继承、指针等概念,因此Java语言具有功能强大和简单易用两个特征。Java语言作为静态面向对象编程语言的代表,极好地实现了面向对象理论,允许程序员以优雅的思维方式进行复杂的编程。

你好,按照你的要求代码如下,可以直接运行

import java.awt.EventQueue;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.KeyAdapter;
import java.awt.event.KeyEvent;
import java.util.Arrays;

import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JScrollPane;
import javax.swing.JTextArea;

public class SplitFrame extends JFrame {

private JTextArea textArea_1;
private JTextArea textArea;

public static void main(String args[]) {
EventQueue.invokeLater(new Runnable() {
public void run() {
try {
SplitFrame frame = new SplitFrame();
frame.setVisible(true);
} catch (Exception e) {
e.printStackTrace();
}
}
});
}

public SplitFrame() {
super();
getContentPane().setLayout(null);
setBounds(100, 100, 500, 383);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

final JButton button = new JButton();
button.addActionListener(new ActionListener() {
public void actionPerformed(final ActionEvent e) {
textArea.setText(null);
textArea_1.setText(null);
}
});
button.setText("清空");
button.setBounds(195, 310, 106, 28);
getContentPane().add(button);

final JScrollPane scrollPane = new JScrollPane();
scrollPane.setBounds(23, 46, 207, 240);
getContentPane().add(scrollPane);

textArea = new JTextArea();
scrollPane.setViewportView(textArea);
textArea.addKeyListener(new KeyAdapter() {
public void keyReleased(final KeyEvent e) {
String str = textArea.getText();
String[] a = str.split("[ ,
]");
Arrays.sort(a);
textArea_1.setText(null);
for (String s : a) {
if (!"".equals(s.trim())) {
textArea_1.append(s + "
");
}
}
}
});

final JScrollPane scrollPane_1 = new JScrollPane();
scrollPane_1.setBounds(252, 46, 207, 240);
getContentPane().add(scrollPane_1);

textArea_1 = new JTextArea();
scrollPane_1.setViewportView(textArea_1);
textArea_1.setEditable(false);

final JLabel label = new JLabel();
label.setText("在此输入");
label.setBounds(93, 22, 66, 18);
getContentPane().add(label);

final JLabel label_1 = new JLabel();
label_1.setText("即时排序");
label_1.setBounds(328, 22, 66, 18);
getContentPane().add(label_1);
}
}

//:SaveContents.java
import java.awt.event.*;
import java.io.*;
import javax.swing.*;
public class SaveContents extends JFrame implements ActionListener{
public static void main(String[] args) {new SaveContents().setVisible(true);}
private JTextField cont;
private JButton save;
private String filePath="c:/cont.txt";//文件的路径
public SaveContents(){
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
this.getContentPane().setLayout(null);
this.setSize(205,130);
this.setLocationRelativeTo(null);
cont = new JTextField();
cont.setBounds(10,10,180,20);
add(cont);
save=new JButton("Save");
save.setBounds(110,50,78,22);
add(save);
save.addActionListener(this);
}
public void actionPerformed(ActionEvent e) {
try {save();} catch (Exception e1) {}
}
//保存内容
private void save() throws Exception{
File f = new File(filePath);
FileWriter fw = new FileWriter(f);
fw.write(cont.getText());
fw.flush();
fw.close();
}
}

import java.util.*;
import java.io.*;
import java.awt.*;
import javax.swing.*;
import java.awt.event.*;

class MyWindow extends JFrame implements ActionListener{
JTextArea text; JButton button;
FileWriter writefile;BufferedWriter out;
MyWindow(){
super("缓冲式样流的输出");
Container con=this.getContentPane();
text=new JTextArea(20,30);
text.setBackground(Color.cyan);
button=new JButton("写文件");
button.addActionListener(this);
con.setLayout(new BorderLayout());
con.setSize(400,400);con.setVisible(true);
con.add(text,"Center"); con.add(button,"South");
try{
writefile =new FileWriter("line.txt");
out=new BufferedWriter(writefile);
}catch(IOException e){}
}
public void actionPerformed(ActionEvent e){
String s;
if(e.getSource()==button){
try{
out.write(text.getText(),0,(text.getText()).length());
out.flush();
text.setText(null);

}catch(IOException ex)
{
System.out.println(ex);
}
}
}
}

public class Example9_3{
public static void main(String []args){
MyWindow myWin=new MyWindow();
myWin.setVisible(true);
}
}

java设计一个求三角形面积的图形界面,要求通过3个输入框输入3个边长
答:import java.awt.event.ActionEvent;import java.awt.event.ActionListener;import javax.swing.*;public class TriangleAreaCalculator extends JFrame { private JLabel label1, label2, label3, resultLabel, errorLabel;private JTextField tf1, tf2, tf3;private JButton calculateButton;public TriangleA...

JAVA编程:编写一个图形界面的Application程序
答:import java.awt.event.*;import java.io.*;import javax.swing.*;public class SaveContents extends JFrame implements ActionListener{ public static void main(String[] args) {new SaveContents().setVisible(true);} private JTextField cont;private JButton save;private String filePath="c:/c...

Java编程 设计一个图形用户界面。界面包括三个单选按钮、两个复选框...
答:程序如下:import java.awt.FlowLayout;import java.awt.event.ActionEvent;import java.awt.event.ActionListener;import javax.swing.ButtonGroup;import javax.swing.JButton;import javax.swing.JCheckBox;import javax.swing.JFrame;import javax.swing.JPanel;import javax.swing.JRadioButton;import java...

java编程采用图形界面实现两个内容的交换,图形界面如下图
答:在程序的actionPerformed方法中,程序将label1和label2的内容交换。具体实现是,首先使用label1.getText()获取label1的内容,并将其保存到一个临时变量temp中;然后,将label1的内容设置为label2的内容,将label2的内容设置为temp的值。这样,label1和label2的内容就被互换了。在main方法中,程序创建了Swap...

java编程实现一个学生信息管理系统的图形界面
答:public 学生信息图形界面() { //构造方法 //界面显示问题 super("学生信息图形界面");setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);setSize(320, 300);setVisible(true);Container content = getContentPane();JPanel jp1 = new JPanel(); //创建一个面板 JLabel label = new JLabel("...

java图形界面编程
答:1、Javac welcome.java后生成welcome.class 2、在跟welcome.class同一级的目录下新建一个文本文件,并输入: 3、保存并将文件名改为welcome.html (这个html文件的名字任意,在这边我用welcome)4、在cmd中输入appletviewer welcome.html便可以看见你的applet了 或直接把这个welcome.html拖入浏览器运行,...

编写一个图形界面的Application程序,包括两个文本框和一个按钮。
答:public static void main(String args[]) { JFrame frame = new JFrame();frame.setLayout(new FlowLayout(FlowLayout.LEFT));final JTextArea textArea1 = new JTextArea(20, 30);final JTextArea textArea2 = new JTextArea(20, 30);JButton button = new JButton("=>");button.addAction...

怎样用java编写图形界面的Application程序?
答:java编写图形界面需要用到swing等组件,可以在eclipse中安装windowbuilder来开发窗体,自动生成窗体代码,然后自己再根据需要修改,如:package mainFrame;import java.awt.EventQueue;import java.awt.event.MouseAdapter;import java.awt.event.MouseEvent;import javax.swing.ImageIcon;import javax.swing.JButton...

JAVA 编写一个java图形GUI程序,比较大小数并输出
答:1.首先定义三个输入框 JTextField firstNumber;JTextField secontdNumber;JTextField maxNumber;2.然后怎样生成并把它们放到界面上我就不多说了。3.接下来生成最大数按钮maxNumberButton和关闭按钮closeButton,并放在界面上。然后让maxnNumberButton监听鼠标单击事件 maxNumberButton.addMouseListener(new Mouse...

用java怎么编写一个图形界面应用程序,其中包含一个按钮。当鼠标移到...
答:{ public void mouseEntered(java.awt.event.MouseEvent e) { jButton.setVisible(false);} public void mouseExited(java.awt.event.MouseEvent e) { jButton.setVisible(true);} });} return jButton;} public static void main(String args[]){ new HideButton().setVisible(true);} } ...

IT评价网,数码产品家用电器电子设备等点评来自于网友使用感受交流,不对其内容作任何保证

联系反馈
Copyright© IT评价网