Java教程

Java知识点复习:Day27

本文主要是介绍Java知识点复习:Day27,对大家解决编程问题具有一定的参考价值,需要的程序猿们随着小编来一起学习吧!

课堂实践

package Demo01;

import java.awt.Container;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.JButton;
import javax.swing.JDialog;
import javax.swing.JFrame;
//上次失败内容
public class DialogDemo01 extends JDialog {
	
	public DialogDemo01(JFrame jframe) {
		
		super(jframe,false);
		this.setBounds(100,100,500,500);
	}
	
	
	
	public static void main(String[] args) {
		JFrame j = new JFrame();
		j.setVisible(true);
		j.setBounds(100,100,700,500);
		
		
		
		j.setDefaultCloseOperation(EXIT_ON_CLOSE);
		
		Container container = j.getContentPane();
		
		container.setLayout(null);
		
		JButton button = new JButton("我要登录");
		button.setBounds(30,30,200,50);
		button.addActionListener(new ActionListener() {
			DialogDemo01 s = new DialogDemo01(j);
			
			
			
			@Override
			public void actionPerformed(ActionEvent e) {
				
				System.out.println("我被点击了");
			}		
		});
			
			
		
	
		container.add(button);
		
		
		}
}

package Demo02;

import java.awt.Container;
import java.awt.GridLayout;

import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JPanel;
/*
 * 
 * 面板作为容器不能单独存在,必须放在其他容器里面 JFrame , JDialog
 * 
 * 
 * 
 */
public class JPaneDemo extends JFrame{
	
		public JPaneDemo() {
			Container container1 = this.getContentPane();
			container1.setLayout(new GridLayout(2,1,10,10));
			
			JPanel panel = new JPanel(new GridLayout(1,3));
			panel.add(new JButton("1"));
			panel.add(new JButton("2"));
			panel.add(new JButton("3"));
			
			container1.add(panel);
			
			this.setDefaultCloseOperation(EXIT_ON_CLOSE);
			this.setVisible(true);
			this.setBounds(100,100,500,500);
		}
	
		
		public static void main(String[] args) {
		new JPaneDemo();
	}
}

package Demo02;

import java.awt.Container;
import java.awt.GridLayout;

import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTextArea;
/*
 * 
 * 面板作为容器不能单独存在,必须放在其他容器里面 JFrame , JDialog
 * 
 * 
 * 
 */
public class JScrollDemo extends JFrame{
	
		public JScrollDemo() {
			Container container1 = this.getContentPane();
			
			
			
			
			// 文本域
			JTextArea textarea = new JTextArea(20,50);
			textarea.setText("大数据五班");
			
			// scroll 面板
			 JScrollPane  scrollpane = new JScrollPane(textarea);
			//JPanel  scrollpane = new JPanel();
			//scrollpane.add(textarea);
			container1.add(scrollpane);
			
			
			
			
			
			
			this.setDefaultCloseOperation(EXIT_ON_CLOSE);
			this.setVisible(true);
			this.setBounds(100,100,500,500);
		}
	
		
		public static void main(String[] args) {
		new JScrollDemo();
	}
}

package Demo03;

import java.awt.BorderLayout;
import java.awt.FlowLayout;

import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.WindowConstants;

public class TestBorderLayout {
	
	
	
	public static void main(String[] args) {
		JFrame j = new JFrame();
		j.setVisible(true);
		j.setBounds(100,100,700,500);
		j.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
		
		
		JButton button1 = new JButton("east");
		JButton button2 = new JButton("west");
		JButton button3 = new JButton("south");
		JButton button4 = new JButton("north");
		JButton button5 = new JButton("center");
		
		
		j.add(button1,BorderLayout.EAST);
		j.add(button2,BorderLayout.WEST);
		j.add(button3,BorderLayout.SOUTH);
		j.add(button4,BorderLayout.NORTH);
		j.add(button5,BorderLayout.CENTER);
		
		
	}
}

package Demo03;

import java.awt.FlowLayout;

import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.WindowConstants;

public class TestFlowLayout2 {
	
	// 流失布局
	
	public static void main(String[] args) {
		JFrame j = new JFrame();
		j.setVisible(true);
		j.setBounds(100,100,700,500);
		j.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
		// j.setLayout(new FlowLayout()); 不传参数默认居中
		
		j.setLayout(new FlowLayout(FlowLayout.LEFT));
		
		
		JButton button1 = new JButton("button1");
		JButton button2 = new JButton("button2");
		JButton button3 = new JButton("button3");
		JButton button4 = new JButton("button4");
		JButton button5 = new JButton("button5");
		JButton button6 = new JButton("button6");
		
		j.add(button1);
		j.add(button2);
		j.add(button3);
		j.add(button4);
		j.add(button5);
		j.add(button6);
		
	}
}

package Demo03;

import java.awt.FlowLayout;
import java.awt.GridLayout;

import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.WindowConstants;

public class TestGrid {
	
	// 流失布局
	
	public static void main(String[] args) {
		JFrame j = new JFrame();
		j.setVisible(true);
		j.setBounds(100,100,700,500);
		j.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
		
		
		j.setLayout(new GridLayout(3,2));
		
		
		JButton button1 = new JButton("button1");
		
		JButton button2 = new JButton("button2");
		
		JButton button3 = new JButton("button3");
		JButton button4 = new JButton("button4");
		JButton button5 = new JButton("button5");
		//JButton button6 = new JButton("button6");
		
		j.add(button1);
		j.add(button2);
		j.add(button3);
		j.add(button4);
		j.add(button5);
		//j.add(button6);
		//j.pack();
		
	}
}

package Demo04;

import java.awt.BorderLayout;
import java.awt.Container;
import java.awt.GridLayout;

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 javax.swing.JScrollPane;
import javax.swing.JTextArea;
/*
 * 
 * 面板作为容器不能单独存在,必须放在
 * 
 * 
 * 
 */
public class CheckBox extends JFrame{
	
		public CheckBox() {
			Container container1 = this.getContentPane();
			
			JCheckBox checkbox1 = new JCheckBox("checkbox1");
			JCheckBox checkbox2 = new JCheckBox("checkbox2");
			JCheckBox checkbox3 = new JCheckBox("checkbox3");
			
			
			
			container1.add(checkbox1,BorderLayout.CENTER);
			container1.add(checkbox2,BorderLayout.NORTH);
			container1.add(checkbox3,BorderLayout.SOUTH);
			
			
			JPanel panel = new JPanel(new GridLayout(1,3));
			
			
			container1.add(panel);
			
			this.setDefaultCloseOperation(EXIT_ON_CLOSE);
			this.setVisible(true);
			this.setBounds(100,100,500,500);
		}
	
		
		public static void main(String[] args) {
		new CheckBox();
	}
}

package Demo04;

import java.awt.BorderLayout;
import java.awt.Container;
import java.awt.GridLayout;

import javax.swing.ButtonGroup;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.JRadioButton;
import javax.swing.JScrollPane;
import javax.swing.JTextArea;
/*
 * 
 * 面板作为容器不能单独存在,必须放在其他容器里面 JFrame , JDialog
 * 
 * 
 * 
 */
public class RadioButon extends JFrame{
	
		public RadioButon() {
			Container container1 = this.getContentPane();
			// 单选框
			JRadioButton radiobutton1 = new JRadioButton("单选1");
			JRadioButton radiobutton2 = new JRadioButton("JRadioButton3");
			JRadioButton radiobutton3 = new JRadioButton("JRadioButton3");
			JRadioButton radiobutton4 = new JRadioButton("JRadioButton4");
			
			//在一个group里面只能有一个container1.add(radiobutton3,BorderLayout.SOUTH);被选中
			
			ButtonGroup group = new ButtonGroup();
			group.add(radiobutton1);
			group.add(radiobutton2);
			group.add(radiobutton3);
			
			container1.add(radiobutton1,BorderLayout.CENTER);
			container1.add(radiobutton2,BorderLayout.NORTH);
			container1.add(radiobutton3,BorderLayout.SOUTH);
			container1.add(radiobutton4,BorderLayout.EAST);
			
			
			
			
			
			
			this.setDefaultCloseOperation(EXIT_ON_CLOSE);
			this.setVisible(true);
			this.setBounds(100,100,500,500);
		}
	
		
		public static void main(String[] args) {
		new RadioButon();
	}
}

package Demo05;

import java.awt.Container;
import java.awt.GridLayout;

import javax.swing.ButtonGroup;
import javax.swing.JButton;
import javax.swing.JComboBox;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.JRadioButton;
import javax.swing.JScrollPane;
import javax.swing.JTextArea;
/*
 * 
 * 面板作为容器不能单独存在,必须放在其他容器里面 JFrame , JDialog
 * 
 * 
 * 
 */
public class TextComBoxDemo01 extends JFrame{
	
		public TextComBoxDemo01() {
			Container container1 = this.getContentPane();
			// 下拉框
			JComboBox status = new JComboBox();
			status.addItem(null);
			status.addItem("正在睡觉");
			status.addItem("准备睡觉");
			status.addItem("看电视");
			
			container1.add(status);
			
			
			
			
			
			
			this.setDefaultCloseOperation(EXIT_ON_CLOSE);
			this.setVisible(true);
			this.setBounds(100,100,500,500);
		}
	
		
		public static void main(String[] args) {
		new TextComBoxDemo01();
	}
}

package Demo05;

import java.awt.Container;
import java.awt.GridLayout;
import java.util.Vector;

import javax.swing.ButtonGroup;
import javax.swing.JButton;
import javax.swing.JComboBox;
import javax.swing.JFrame;
import javax.swing.JList;
import javax.swing.JPanel;
import javax.swing.JRadioButton;
import javax.swing.JScrollPane;
import javax.swing.JTextArea;
/*
 * 
 * 面板作为容器不能单独存在,必须放在其他容器里面 JFrame , JDialog
 * 
 * 
 * 
 */
public class TextComBoxDemo02 extends JFrame{
	
		public TextComBoxDemo02() {
			Container container1 = this.getContentPane();
			// 下拉框
			
			// String[] contents = {"1","五班","java"}
			Vector<Object> contents = new Vector();
			JList jlist = new JList(contents);
			
			contents.add("五班");
			
			contents.add("爱学习");
			contents.add("打游戏");
			contents.add("兼得");
			
			
			container1.add(jlist);
			this.setDefaultCloseOperation(EXIT_ON_CLOSE);
			this.setVisible(true);
			this.setBounds(100,100,500,500);
		}
	
		
		public static void main(String[] args) {
		new TextComBoxDemo02();
	}
}

在这里插入图片描述

在这里插入图片描述
在这里插入图片描述

在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述


2020080605036

这篇关于Java知识点复习:Day27的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!