Java Swing简单样例

     大学时候Java 学的很简单,当时玩的也多,学了就忘。额外买的java书看了几章就不看了,想想真是惭愧。最近由于实验室需要对于别人的东西做一点简单测试,我也就花了1天重新写了一个简单的Jframe界面。

   非常非常简单,本来都不好意思放上来,不过想着一点是一点,大学没不好好学习靠着以前的底子写一点简单东西

    1.JFileChooser选择路径在JTextField上展示

    2.数据浏览功能,txt数据用一个新的frame展示出来

    3.bean结构数据降序排列,计算时间

     4.将文件输出保存到当前工程文件夹下,按照文件名_type_日期(win下是\r\n换行、日期中符号  :  不能在文件名中出现)


需要排序的bean:

public class Store {
	private String str1;
	private String str2;
	private double rs;
	
	public String getStr1() {
		return str1;
	}
	public void setStr1(String str1) {
		this.str1 = str1;
	}
	public String getStr2() {
		return str2;
	}
	public void setStr2(String str2) {
		this.str2 = str2;
	}
	public double getRs() {
		return rs;
	}
	public void setRs(double rs) {
		this.rs = rs;
	}

}
主函数所在类:
import javax.swing.*;

import sentsim.CompSim;

import java.util.*;
import java.util.List;
import java.awt.*;
import java.lang.System;
import java.text.SimpleDateFormat;
import java.awt.event.*;
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.UnsupportedEncodingException;

class Intcom implements Comparator<Store> {
	public int compare(Store A, Store B) {
		if (A.getRs() > B.getRs())
			return -1;
		else if(A.getRs() == B.getRs()) return 0;
		else return 1;
	}
}

@SuppressWarnings("serial")
public class SimiliarFrame extends JFrame implements ActionListener {
	JButton btn;
	JButton Watch1, Choose1;
	JButton Watch2, Choose2;
	JLabel b1, b2, b3;
	JTextField t1, t2, t3;
	JFileChooser fc = new JFileChooser();
	TextArea area;
	JPanel p1, p2;

	public SimiliarFrame() {
		//super();
		btn = new JButton("开始运算");
		Choose1 = new JButton("文件选择");
		Choose2 = new JButton("文件选择");
		Watch1 = new JButton("数据浏览");
		Watch2 = new JButton("数据浏览");
		b1 = new JLabel("文件路径1:");
		b2 = new JLabel("文件路径2:");
		b3 = new JLabel("得分最高的多少个:");

		t1 = new JTextField(10); 
		t2 = new JTextField(10);
		t3 = new JTextField(10);

		btn.addActionListener(this);
		Choose1.addActionListener(this);
		Choose2.addActionListener(this);
		Watch1.addActionListener(this);
		Watch2.addActionListener(this);

		p1 = new JPanel();
		// row cloumn 水
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 2
    评论
以下是一个简单Java Swing 程序,演示了如何创建和使用 JRadioButton 组件: ```java import javax.swing.*; import java.awt.*; import java.awt.event.*; public class JRadioButtonDemo extends JFrame implements ActionListener { private JRadioButton radioButton1, radioButton2, radioButton3; private JButton button; public JRadioButtonDemo() { // 创建窗口和布局管理器 setTitle("JRadioButton Demo"); setSize(300, 150); setLayout(new GridLayout(4, 1)); // 创建三个单选按钮和一个按钮 radioButton1 = new JRadioButton("Option 1"); radioButton2 = new JRadioButton("Option 2"); radioButton3 = new JRadioButton("Option 3"); button = new JButton("Submit"); // 将三个单选按钮添加到 ButtonGroup 中 ButtonGroup group = new ButtonGroup(); group.add(radioButton1); group.add(radioButton2); group.add(radioButton3); // 添加组件并注册监听器 add(radioButton1); add(radioButton2); add(radioButton3); add(button); button.addActionListener(this); setVisible(true); } public void actionPerformed(ActionEvent event) { // 处理按钮的点击事件 if (radioButton1.isSelected()) { System.out.println("You selected Option 1."); } else if (radioButton2.isSelected()) { System.out.println("You selected Option 2."); } else if (radioButton3.isSelected()) { System.out.println("You selected Option 3."); } else { System.out.println("You didn't select any option."); } } public static void main(String[] args) { new JRadioButtonDemo(); } } ``` 以上程序创建了一个窗口,其中包含三个单选按钮和一个按钮。单选按钮被添加到一个 ButtonGroup 中,以确保只能选择一个选项。当用户点击按钮时,程序会检查哪个单选按钮被选中,并输出相应的信息。
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值