如何用java图形用户界面实现下面的功能:1.运行时出现如下面板 2.单击改变字体大小时可以使得字体大小加2

Java如何实现界面1,之后当用鼠标单击按钮时出现界面2。~

在事件方法中再new个新的并更新按钮文本再显示,如果只是改变按钮的文本,把actionPerformed方法中的最后注释掉的两句留下,前面全删除就可以了。
import java.awt.FlowLayout;import java.awt.event.ActionEvent;import java.awt.event.ActionListener;import javax.swing.JButton;import javax.swing.JFrame;import javax.swing.SwingUtilities;public class Win1 extends JFrame implements ActionListener{ private JButton btn1=new JButton("上课!"); private JButton btn2=new JButton("下课!"); public Win1() { btn1.addActionListener(this); btn2.addActionListener(this); this.setLayout(new FlowLayout()); this.add(btn1); this.add(btn2); this.setTitle("事件处理示例"); this.setSize(300,100); this.setLocationRelativeTo(null);; this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); } @Override public void actionPerformed(ActionEvent e) { Win1 win=new Win1(); win.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE); win.setLocation(this.getX()+310,this.getY()); win.btn1.setText("上课啦!!!"); win.btn2.setText("下课啦!!!"); win.setVisible(true); //如果只是改变按钮文本,删除上面6行代码,请用下面的这2句 //this.btn1.setText("上课啦!!!"); //this.btn2.setText("下课啦!!!"); } public static void main(String[] args) { SwingUtilities.invokeLater(new Runnable() { @Override public void run() { Win1 win=new Win1(); win.setVisible(true); } }); }}

import java.awt.Dimension;
import java.awt.FlowLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.*;

public class Demo extends JFrame implements ActionListener{

private JButton jb;//定义按钮
private JPanel jp;//定义面板
public Demo(){//构造函数
jb = new JButton("单击这里");//实例化按钮对象
jb.addActionListener(this);//添加侦听器

jp = new JPanel();//实例化面板
jp.setLayout(new FlowLayout());
jp.setSize(400,300);
jp.setVisible(true);

jp.add(jb);
jb.setPreferredSize(new Dimension(90, 30));
jb.setVisible(true);

this.add(jp);
this.setTitle("窗口1");
this.setSize(400,300);
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
this.setVisible(true);
this. setLocationRelativeTo(null);
}

public static void main(String[] args){
System.out.println("程序开始运行···");
new Demo();
}

public void actionPerformed(ActionEvent e) {
// TODO Auto-generated method stub
String arg = e.getActionCommand();//获取事件侦听参数
if (arg == "单击这里") {
Demo d = new Demo();
d.setTitle("窗口2");
d.setBounds(10,10,400,300);
}
}
}

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

import javax.swing.*;
public class HelpYou extends JFrame{

public JButton up = new JButton("改变字体大小");
public JButton left = new JButton("设置字体");
public JButton down = new JButton("打开调色面板");
public JTextArea area = new JTextArea("这是有一个文本区,用来输入文本");
public int fontSize = 12;//设置默认字体大小为12
public JPanel panel = new JPanel();
public Object SetFont;
public HelpYou(){
innit();
}
public void innit(){//初始化面板
BorderLayout bl = new BorderLayout();
panel.setLayout(bl);
panel.add(up,bl.NORTH);
panel.add(left,bl.WEST);
panel.add(down,bl.SOUTH);
panel.add(area,bl.CENTER);
area.setLineWrap(true);//设置文本域自动换行
up.addActionListener(new MyClick());
left.addActionListener(new MyClick());
down.addActionListener(new MyClick());
this.setContentPane(panel);
this.setTitle("My Java");
this.setSize(400,300);
this.setVisible(true);
this.setResizable(false);//设置窗体大小不可改
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
class MyClick implements ActionListener{
public void actionPerformed(ActionEvent e) {
if(e.getSource()==up){
fontSize+=2;
area.setFont(new Font("宋体",Font.PLAIN,fontSize));
}
if(e.getSource()==left){
SetFont sf = new SetFont();
}
if(e.getSource()==down){
SetColor sc = new SetColor();
}
}
}
class SetColor extends JFrame{//设置字体的面板
public JButton ok = new JButton("确定");
public JButton cancel = new JButton("取消");
public JPanel panel = new JPanel();
public SetColor(){
innit();
}
public void innit(){
JPanel colorPanel = new JPanel();
colorPanel.setLayout(new GridLayout(1, 8));//一共设置了7种颜色
JButton[] cButton = new JButton[8];
for(int i=0;i<8;i++){
cButton[i] = new JButton();//对颜色按钮初始化
colorPanel.add(cButton[i]);
}
cButton[0].setBackground(Color.RED);
cButton[1].setBackground(Color.ORANGE);
cButton[2].setBackground(Color.YELLOW);
cButton[3].setBackground(Color.GREEN);
cButton[4].setBackground(Color.BLUE);
cButton[5].setBackground(Color.CYAN);
cButton[6].setBackground(Color.PINK);
cButton[7].setBackground(Color.BLACK);
colorPanel.add(cButton[0]);
colorPanel.setLayout(new FlowLayout());//设置默认布局
panel.add(colorPanel);
panel.add(ok);
panel.add(cancel);
this.setSize(350,120);
this.setLocation(0,50);
this.setContentPane(panel);
this.setVisible(true);
this.setResizable(false);//设置窗体大小不可改
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
}
class SetFont extends JFrame{//设置字体的面板
public JButton ok = new JButton("确定");
public JButton cancel = new JButton("取消");
public JComboBox size = new JComboBox();
public JComboBox type = new JComboBox();
public JPanel fontPanel = new JPanel();
public SetFont(){
innit();
}
public void innit(){
fontPanel.setLayout(new FlowLayout());//设置默认布局
fontPanel.add(size);
fontPanel.add(type);
fontPanel.add(ok);
fontPanel.add(cancel);
size.addItem("选择字体");
size.addItem("12");
size.addItem("20");
size.addItem("30");
size.addItem("50");
type.addItem("选择字形");
type.addItem("宋体");
type.addItem("黑体");
type.addItem("微软雅黑");
this.setSize(400,100);
this.setLocation(0,100);
this.setContentPane(fontPanel);
this.setVisible(true);
this.setResizable(false);//设置窗体大小不可改
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}

}
public static void main(String[] args) {
HelpYou hy = new HelpYou();
}
}

事件监听不会加?

java用网络编程和图形用户界面实现atm机的存,取款,转账,查询,修改密码...
答:import javax.swing.JOptionPane;public class Account { private String name;private String account;private String data;private String ID;private double balance;public Account(String name,double balance,String data,String ID){ this.name = name;this.balance = balance;this.data=data;this.ID=...

JAVA中图形用户界面不同类之间的调用怎么画,用什么画?
答:首先要应用GUI相关的包比如import java.awt.*;import javax.swing.*;给你个例子吧 public class Test extends JFrame{ MyPanel mp=null;public static void main(String[] args){ // TODO Auto-generated method stub Test jf= new Test();} public Test(){ mp=new MyPanel();this.add(mp)...

用java怎么编写一个图形界面应用程序,其中包含一个按钮。当鼠标移到...
答:import javax.swing.JFrame;import java.awt.Dimension;import javax.swing.JPanel;import java.awt.GridBagLayout;import javax.swing.JButton;import java.awt.Rectangle;public class HideButton extends JFrame { private JPanel jPanel = null;private JButton jButton = null;/ This method ...

java设计一个求三角形面积的图形界面,要求通过3个输入框输入3个边长...
答:void main(String[] args) { TriangleAreaCalculator calculator = new TriangleAreaCalculator();calculator.setVisible(true);} } ```通过绑定按钮的监听器,在输入三边长度后单击 “Calculate” 按钮,程序将计算三角形的面积,并在下方展示计算结果,当用户输入不合法数据时,也会在下方展示错误提示。

java,swing,awt,图形用户界面:怎么搜索一个本地文本文件并将该文件内容...
答:掌握IO知识,可以做到:搜索文件,读取文本内容,写入文本内容 掌握swing/awt的事件处理机制,可以实现:点击某个按钮, 会触发相应的事件处理 效果图 参考代码 : 注意填写3个方法 import java.awt.*;import java.awt.event.*;import javax.swing.*;//该窗口继承自JFrame. 实现了ActionListener接口public ...

java图形用户界面
答:import java.awt.*;import java.awt.event.*;import java.applet.*;public class III extends Applet { boolean isStandalone = false;BorderLayout borderLayout1 = new BorderLayout();Panel panel1 = new Panel();TextArea textArea1 = new TextArea();Label label1 = new Label();Choice ...

使用JAVA编程万年历要求:使用图形用户界面;实现日期与星期的查询。_百...
答:这是我刚做出来的,时间紧迫,做得有些粗糙,但是你要的功能基本实现了!import java.awt.*;import java.text.*;import javax.swing.*;import java.awt.event.*;import java.util.*;//import java.util.Timer;public class DataSimple implements ItemListener { JFrame mainFrame;JLabel yearLabel,...

java程序设计,图形用户界面的,
答:java程序设计,图形用户界面的, 需原创,最好只用到importjava.awt.*;importjavax.swing.*;importjava.awt.eve这几个,因为才初学,请大大帮忙,附功能描述,结构分析。QQ451042440... 需原创,最好只用到import java.awt.*; import javax.swing.*; import java.awt.eve这几个,因为才初学,请大大帮忙,附功能描述,...

JAVA图形用户界面
答:import java.awt.event.ActionEvent;import java.awt.event.ActionListener;import javax.swing.JButton;import javax.swing.JComboBox;import javax.swing.JFrame;import javax.swing.JOptionPane;import javax.swing.JTextField;public class Test { public static void main(String[] args) { JFrame jf ...

利用java写一个用户注册图形界面
答:写了个最简单的界面,其它要求自己可以添加和修改.package com.frames.member;import java.awt.BorderLayout;import java.awt.GridLayout;import java.awt.event.ActionEvent;import java.awt.event.ActionListener;import javax.swing.JButton;import javax.swing.JComboBox;import javax.swing.JFrame;import ...

IT评价网,数码产品家用电器电子设备等点评来自于网友使用感受交流,不对其内容作任何保证

联系反馈
Copyright© IT评价网