swing组件
Created|Updated
|Post Views:



Related Articles
2020-04-02
JDialog窗体
在父窗体中调用对话框12345678910111213141516171819202122232425262728293031import java.awt.*;import java.awt.event.*;import javax.swing.*;public class Demo extends JDialog{ public Demo() { setBounds(200, 200, 100, 100); Container c = getContentPane();//创建容器 c.add(new JLabel("我是对话框")); } public static void main(String[] args) { JFrame jf = new JFrame("父窗体");//创建父窗体 jf.setVisible(true);//可见 jf.setDefaultCloseOperation(EXIT_ON_CLOSE); jf.setBounds(200, 200,...
2020-12-18
Calculator
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110import java.awt.FlowLayout;import java.awt.event.ActionEvent;import java.awt.event.ActionListener;import java.io.File;import java.io.FileWriter;import java.io.IOException;import javax.swing.*;public class Calculator extends JFrame implements...
2020-12-18
Menu
JMenuBar(菜单条),这一栏可以装菜单。 JMenu(菜单),只有菜单才能有分支 JMenuItem(菜单项目),最终选项 菜单和菜单条能用add中嵌套菜单,和菜单项目。 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253import javax.swing.JFrame;import java.awt.FlowLayout;import javax.swing.*;public class Menu extends JFrame { //声明组件 JMenuBar m; JMenu menu, subMenu, save_as,option; JMenuItem item1, item2, save, desktop, document; public Menu(){ init(); this.setLayout(new...
2020-04-02
JFrame窗体
123456789101112131415161718192021222324package 创建JFrame窗体;import java.awt.*;import javax.swing.*;//继承JFrame,以下方法都来源于JFrame类public class Example1 extends JFrame{//让Example1成为一个窗体 public Example1() {//构造方法,与类同名 setVisible(true);//让窗口可见 setTitle("Hello");//窗口标题 setDefaultCloseOperation(EXIT_ON_CLOSE);//窗口关闭,并结束程序 setBounds(200, 200, 300, 200);//窗口大小,和坐标 Container c = getContentPane();//获取窗口容器 c.setBackground(Color.white);//背景颜色 JLabel xxx = new...
2020-04-02
Label类(标签)
方法 改变字体setFont(,,,) 获取urlURL url = Demo.class.getResource(“file.png”) 获取url路径的文件Icon icon = new ImageIcon(url) 添加图片setIcon() 示例 12345678910111213141516171819202122232425package 标签;import java.awt.Container;import java.awt.Font;import javax.swing.*;public class Demo extends JFrame{ public Demo() { setDefaultCloseOperation(EXIT_ON_CLOSE); setBounds(200, 200, 300, 200); Container c = getContentPane(); JLabel l = new JLabel("My name is...
2020-04-02
Layout(布局)
1container.setLayout(new Layout的类()) null布局传给Layout()null参数再setBounds(,,,,)按钮的坐标和大小 123456789101112131415161718192021222324package 绝对布局;import java.awt.*;import javax.swing.*;public class Demo extends JFrame{ public Demo() { setBounds(200, 200, 500, 300); setDefaultCloseOperation(EXIT_ON_CLOSE); Container c = getContentPane(); c.setLayout(null);//设置布局 JButton b1 = new JButton("按钮1");//新建按钮对象 JButton b2 = new JButton("按钮2"); b1.setBounds(20, 30, 80,...
