「java源码swing」JAVA源码下载

博主:adminadmin 2022-11-30 09:01:05 65

本篇文章给大家谈谈java源码swing,以及JAVA源码下载对应的知识点,希望对各位有所帮助,不要忘了收藏本站喔。

本文目录一览:

java swing程序怎么运行?

import java.awt.*;

import javax.swing.*;

public class GUI extends JFrame{

    private JMenuBar mb=new JMenuBar();

    private JMenu mm=new JMenu("文件");

    private JMenuItem mi1=new JMenuItem("粘贴");

    private JMenuItem mi2=new JMenuItem("复制");

    private JLabel l=new JLabel();

    public GUI(){

        this.setLayout(null);

        mm.add(mi1);

        mm.add(mi2);

        mb.add(mm);

        this.setJMenuBar(mb);

        l.setText("我的第一个图形用户界面");

        l.setBounds(10,10,450,30);

        this.getContentPane().add(l);

        this.setBounds(330,250,500,150);

        this.setVisible(true);

        this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

    }

    public static void main(String[] args){

        new GUI();

    }

}

java的swing

Swing是一个用于开发Java应用程序用户界面的开发工具包。

以抽象窗口工具包(AWT)为基础使跨平台应用程序可以使用任何可插拔的外观风格。Swing开发人员只用很少的代码就可以利用Swing丰富、灵活的功能和模块化组件来创建优雅的用户界面。 工具包中所有的包都是以swing作为名称,例如javax.swing,javax.swing.event。

求java源代码。使用swing或AWT。实现功能:点击按钮,选择一个txt文本文件,并将txt中

搞定了

package com.monubia;

import java.awt.event.MouseAdapter;

import java.awt.event.MouseEvent;

import java.io.BufferedReader;

import java.io.FileNotFoundException;

import java.io.FileReader;

import java.io.IOException;

import javax.swing.JButton;

import javax.swing.JDialog;

import javax.swing.JFileChooser;

import javax.swing.JTextArea;

import javax.swing.WindowConstants;

import javax.swing.SwingUtilities;

import javax.swing.filechooser.FileNameExtensionFilter;

/**

* This code was edited or generated using CloudGarden's Jigloo

* SWT/Swing GUI Builder, which is free for non-commercial

* use. If Jigloo is being used commercially (ie, by a corporation,

* company or business for any purpose whatever) then you

* should purchase a license for each developer using Jigloo.

* Please visit  for details.

* Use of Jigloo implies acceptance of these licensing terms.

* A COMMERCIAL LICENSE HAS NOT BEEN PURCHASED FOR

* THIS MACHINE, SO JIGLOO OR THIS CODE CANNOT BE USED

* LEGALLY FOR ANY CORPORATE OR COMMERCIAL PURPOSE.

*/

public class Txt extends javax.swing.JFrame {

private JButton jButton_open;

private JTextArea jTextArea1;

/**

* Auto-generated main method to display this JFrame

*/

public static void main(String[] args) {

SwingUtilities.invokeLater(new Runnable() {

public void run() {

Txt inst = new Txt();

inst.setLocationRelativeTo(null);

inst.setVisible(true);

}

});

}

public Txt() {

super();

initGUI();

}

private void initGUI() {

try {

setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);

getContentPane().setLayout(null);

{

jButton_open = new JButton();

getContentPane().add(jButton_open);

jButton_open.setText("Open");

jButton_open.setBounds(155, 114, 92, 49);

jButton_open.addMouseListener(new MouseAdapter() {

public void mouseClicked(MouseEvent evt) {

jButton_openMouseClicked(evt);

}

});

}

{

jTextArea1 = new JTextArea();

getContentPane().add(jTextArea1);

jTextArea1.setBounds(0, 0, 384, 262);

}

pack();

setSize(400, 300);

} catch (Exception e) {

    //add your error handling code here

e.printStackTrace();

}

}

private void jButton_openMouseClicked(MouseEvent evt) {

//点击了打开

JFileChooser open=new JFileChooser();

FileNameExtensionFilter txt= new FileNameExtensionFilter("Txt File", "txt");

open.setFileFilter(txt);

int ret=open.showOpenDialog(this);

if(ret==JFileChooser.APPROVE_OPTION)

{

jButton_open.setOpaque(false);

jButton_open.setVisible(false);

System.out.println(open.getSelectedFile().getAbsolutePath());

try {

BufferedReader br=new BufferedReader(new FileReader(open.getSelectedFile().getAbsolutePath()));

String line=null;

while((line=br.readLine())!=null)

{

jTextArea1.append(line+"\n");

}

} catch (FileNotFoundException e) {

// TODO Auto-generated catch block

e.printStackTrace();

} catch (IOException e) {

// TODO Auto-generated catch block

e.printStackTrace();

}

}

}

}

java源码swing的介绍就聊到这里吧,感谢你花时间阅读本站内容,更多关于JAVA源码下载、java源码swing的信息别忘了在本站进行查找喔。

The End

发布于:2022-11-30,除非注明,否则均为首码项目网原创文章,转载请注明出处。