ZKX's LAB

java图形界面设计代码 求一个简单的java代码:(图形界面)

2020-10-03知识7

java图形界面程序代码

java图形界面设计代码 求一个简单的java代码:(图形界面)

编写一个java图形界面程序,有两个文本输入操作数 不难,尝试着自己写吧。import java.awt.event.ActionEvent;import java.awt.event.ActionListener;import javax.swing.JButton;import javax.swing.JFrame;import javax.swing.JLabel;import javax.swing.JOptionPane;import javax.swing.JPanel;import javax.swing.JTextField;public class SimpleCalc extends JFrame {public static void main(String[]args){new SimpleCalc();}public SimpleCalc(){setSize(500,200);setDefaultCloseOperation(EXIT_ON_CLOSE);setLocationRelativeTo(null);init();setVisible(true);}protected void init(){setTitle(\"Simple Calc\");JPanel p=new JPanel();add(p);JTextField num1=new JTextField(10);p.add(num1);p.add(new JLabel(\"+\"));JTextField num2=new JTextField(10);p.add(num2);p.add(new JLabel(\"=\"));JTextField result=new JTextField(10);result.setEditable(false);p.add(result);JButton calc=new JButton(\"计算\");calc.addActionListener(new CalcListener(num1,num2,result));p.add(calc);}class CalcListener implements ActionListener {private JTextField num1,num2,result;CalcListener。

java图形界面设计代码 求一个简单的java代码:(图形界面)

java图形界面代码 import java.awt.*;import java.awt.event.*;import java.io.*;import javax.swing.*;public class ReadBook extends JFrame {JTextArea jta;JTextField jtf;JButton jb;public ReadBook(){jta=new JTextArea();jtf=new JTextField(30);jtf.setText(\"文件保存路径如c:\\\\ab.txt\");jb=new JButton(\"保存文字\");JPanel jp=new JPanel();jp.add(jtf);jp.add(jb);add(jta);add(jp,BorderLayout.SOUTH);setBounds(500,100,500,380);setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);setVisible(true);jb.addActionListener(new ActionListener(){Overridepublic void actionPerformed(ActionEvent e){核心代码-String path=jtf.getText();File f=new File(path);String txt=jta.getText().replaceAll(\"\\n\",\"\\r\\n\");try {BufferedWriter bw=new BufferedWriter(new FileWriter(f));bw.write(txt);写入文件中bw.close();} catch(Exception e1){e1.printStackTrace();}核心代码-}});}public static void main(String[]args){new ReadBook();}}

java图形界面设计代码 求一个简单的java代码:(图形界面)

求一个简单的java代码:(图形界面) 直接写main函数里了public static void main(String[]args){JFrame ck=new JFrame(\"title\");JPanel mb=new JPanel();mb.setLayout(null);String str=\"test;自己定义要显示什么JTextArea ta=new JTextArea(str);ta.setBounds(0,0,100,30);自己定义文本区在窗口中的位置和大小mb.add(ta);ck.add(mb);ck.setVisible(true);ck.setBounds(200,200,500,500);自己定义窗口位置和大小}

java的图形用户界面程序设计 1、Java在GUI开发方面是个短板,之前awt,还是现在的swing,不管是Application还是java web,它的GUI开发效率都远底于.Net。2、现在Eclipse有几个GUI插件,像VE(Visiual Editor),口碑还不错,但是也不如.net平台或是vb那样的简洁容易。3、NetBeans在Java的GUI开发方面还不错,比Eclipse环境有优势,但还是距离windows的GUI开发差的还很远。试试看吧。

怎样用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;import javax.swing.JLabel;import javax.swing.JPanel;import javax.swing.JPasswordField;import javax.swing.JTextField;import javax.swing.SwingConstants;import javax.swing.UIManager;import javax.swing.UnsupportedLookAndFeelException;import javax.swing.border.EmptyBorder;public class Mian_login extends JFrame {private JPanel contentPane;private JTextField text_LoginName;private JPasswordField Login_password;Launch the application.public static void main(String[]args){EventQueue.invokeLater(new Runnable(){Overridepublic void run(){try {Mian_login frame=new Mian_login();frame.setVisible(true);} catch(Exception e){e。.

java图形界面代码解惑 一般来说.比较常使用的是 JTextArea文本框的无参数构造器进行构造然后可以使用setText(\"文字\")来设置文本,或者getText()方法来获得文本JTextArea jta=new JTextArea();jta.setText(\"你好啊\");String txt=jta.getText();具体例子import java.awt.*;import java.awt.event.*;import java.io.*;import javax.swing.*;public class ReadBook extends JFrame{JTextArea jta;JTextField jtf;JButton jb;public ReadBook(){jta=new JTextArea();jtf=new JTextField(30);jtf.setText(\"文件路径如c:\\\\ab.txt\");jb=new JButton(\"显示文字\");JPanel jp=new JPanel();jp.add(jtf);jp.add(jb);add(jta);add(jp,BorderLayout.SOUTH);setBounds(500,100,500,380);setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);setVisible(true);jb.addActionListener(new ActionListener(){Overridepublic void actionPerformed(ActionEvent e){String path=jtf.getText();File f=new File(path);if(f.exists()&。f.isDirectory()){/存在该文件且不是文件夹try {StringBuilder sb=new StringBuilder();BufferedReader br=new BufferedReader(new FileReader(f));String temp;while((temp=br。.

java编写一个图形界面程序 import java.awt.*;import java.awt.event.*;import java.util.*;import javax.swing.*;import javax.swing.border.Border;class MainFrame extends JFrame {private static final long serialVersionUID=1L;private Map,Integer>;sizes=new HashMap,Integer>;();private Map,Integer>;styles=new HashMap,Integer>;();private Map,Integer>;toppings=new HashMap,Integer>;();public MainFrame(){sizes.put(\"Extra Large\",10);sizes.put(\"Large\",8);sizes.put(\"Medium\",5);sizes.put(\"Small\",3);styles.put(\"Deep Dish\",20);styles.put(\"Regular\",10);styles.put(\"Thin Crust\",5);styles.put(\"Chicago\",3);toppings.put(\"Cheese\",8);toppings.put(\"Tomato\",7);toppings.put(\"Peppers\",6);toppings.put(\"Peperoni\",5);this.setTitle(\"布局及事件处理\");this.setSize(450,350);this.setLayout(new BorderLayout());this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);JLabel lblTitle=new JLabel();lblTitle.setText(\"Pizzeria Juno\");lblTitle.setFont(new Font(\"宋体\",Font.BOLD,36));lblTitle.setHorizontalAlignment(SwingConstants.CENTER);this.add(\"North\",。

#图形界面#string

随机阅读

qrcode
访问手机版