import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class SchoolNet extends JFrame implements ActionListener
{
private JPanel jp=new JPanel();
private JTextField jtf=new JTextField();
private JPasswordField jpf=new JPasswordField();
private JButton[] jbArray={new JButton("连接"),new JButton("退出"),
new JButton("系统"),new JButton("设置")};
private JLabel[] jlArray={new JLabel("用户名"),new JLabel("密码"),
new JLabel("语言"),new JLabel("网卡"),new JLabel("邵阳学院"),
new JLabel("HU NAN SHAO YANG UNIVERSITY"),
new JLabel("Supplicant 3.35-0618")};
private String str1[]={"中文","English"};
private JComboBox jcb1=new JComboBox(str1);
private String str2[]={"VIA Rhine Fast Ethernet Adapt"};
private JComboBox jcb2=new JComboBox(str2);
public SchoolNet()
{
jp.setLayout(null);
for(int i=0;i<4;i++)
{
jlArray[i].setBounds(20,50+i*40,80,25);
jp.add(jlArray[i]);
jbArray[i].setBounds(10+i*80,230,70,20);
jp.add(jbArray[i]);
}
jtf.setBounds(80,48,200,25);
jp.add(jtf);
jpf.setBounds(80,88,200,25);
jp.add(jpf);
jcb1.setBounds(80,128,200,25);
jp.add(jcb1);
jcb2.setBounds(80,170,200,25);
jp.add(jcb2);
Font font=new Font("隶书",0,50);
jlArray[4].setFont(font);
jlArray[4].setBounds(60,0,210,30);
jlArray[4].setOpaque(true);
jlArray[4].setBackground(Color.red);
jp.add(jlArray[4]);
jlArray[5].setBounds(70,30,185,10);
jlArray[5].setOpaque(true);
jlArray[5].setBackground(Color.red);
jp.add(jlArray[5]);
jlArray[6].setBounds(200,210,130,10);
jp.add(jlArray[6]);
jbArray[0].addActionListener(this);
jbArray[1].addActionListener(this);
jbArray[2].addActionListener(this);
jbArray[3].addActionListener(this);
jcb1.addActionListener(this);
this.add(jp);
this.setTitle("邵阳学院网络认证计费系统");
this.setBounds(300,200,340,300);
this.setVisible(true);
}
public void actionPerformed(ActionEvent e)
{
if(e.getSource()==jbArray[0])
{
JOptionPane.showMessageDialog(null,"还没与数据库连接,不能连接","消息!",1);
}
else if(e.getSource()==jbArray[1])
{
System.exit(0);
}
else if(e.getSource()==jbArray[2])
{
JOptionPane.showMessageDialog(null,"邵阳学院校园网","消息!",1);
}
else if(e.getSource()==jbArray[3])
{
JOptionPane.showMessageDialog(null,"没与网络连接,不能进行设置","消息!",1);
}
else if(e.getSource()==jcb1)
{
if(jcb1.getSelectedIndex()==0)
{
jlArray[0].setText("用户名");
jlArray[1].setText("密码");
jlArray[2].setText("语言");
jlArray[3].setText("网卡");
jbArray[0].setText("连接");
jbArray[1].setText("退出");
jbArray[2].setText("系统");
jbArray[3].setText("设置");
}
else if(jcb1.getSelectedIndex()==1)
{
jlArray[0].setText("User");
jlArray[1].setText("PassWord");
jlArray[2].setText("Language");
jlArray[3].setText("Adapter");
jbArray[0].setText("Connect");
jbArray[1].setText("Exit");
jbArray[2].setText("Message");
jbArray[3].setText("Configure");
}
}
}
public static void main(String[] args)
{
SchoolNet sn=new SchoolNet();
}
}
这道程序运行后,,,图形界面基本可以,刚学JAVA,许多方法不太会用,,,如何把“邵阳学院”“HU NAN SHAO YANG UNIVERSITY"的标签的全部背景设成红色了,还有一个问题就是,当我选择英文显示时,,,四个按钮并不能把英文全部显示出来,如何把英文字体字体设置小些,,让其全部显示出来,,,麻烦讲解
import java.awt.event.*;
import javax.swing.*;
public class SchoolNet extends JFrame implements ActionListener
{
private JPanel jp=new JPanel();
private JTextField jtf=new JTextField();
private JPasswordField jpf=new JPasswordField();
private JButton[] jbArray={new JButton("连接"),new JButton("退出"),
new JButton("系统"),new JButton("设置")};
private JLabel[] jlArray={new JLabel("用户名"),new JLabel("密码"),
new JLabel("语言"),new JLabel("网卡"),new JLabel("邵阳学院"),
new JLabel("HU NAN SHAO YANG UNIVERSITY"),
new JLabel("Supplicant 3.35-0618")};
private String str1[]={"中文","English"};
private JComboBox jcb1=new JComboBox(str1);
private String str2[]={"VIA Rhine Fast Ethernet Adapt"};
private JComboBox jcb2=new JComboBox(str2);
public SchoolNet()
{
jp.setLayout(null);
for(int i=0;i<4;i++)
{
jlArray[i].setBounds(20,50+i*40,80,25);
jp.add(jlArray[i]);
jbArray[i].setBounds(10+i*80,230,70,20);
jp.add(jbArray[i]);
}
jtf.setBounds(80,48,200,25);
jp.add(jtf);
jpf.setBounds(80,88,200,25);
jp.add(jpf);
jcb1.setBounds(80,128,200,25);
jp.add(jcb1);
jcb2.setBounds(80,170,200,25);
jp.add(jcb2);
Font font=new Font("隶书",0,50);
jlArray[4].setFont(font);
jlArray[4].setBounds(60,0,210,30);
jlArray[4].setOpaque(true);
jlArray[4].setBackground(Color.red);
jp.add(jlArray[4]);
jlArray[5].setBounds(70,30,185,10);
jlArray[5].setOpaque(true);
jlArray[5].setBackground(Color.red);
jp.add(jlArray[5]);
jlArray[6].setBounds(200,210,130,10);
jp.add(jlArray[6]);
jbArray[0].addActionListener(this);
jbArray[1].addActionListener(this);
jbArray[2].addActionListener(this);
jbArray[3].addActionListener(this);
jcb1.addActionListener(this);
this.add(jp);
this.setTitle("邵阳学院网络认证计费系统");
this.setBounds(300,200,340,300);
this.setVisible(true);
}
public void actionPerformed(ActionEvent e)
{
if(e.getSource()==jbArray[0])
{
JOptionPane.showMessageDialog(null,"还没与数据库连接,不能连接","消息!",1);
}
else if(e.getSource()==jbArray[1])
{
System.exit(0);
}
else if(e.getSource()==jbArray[2])
{
JOptionPane.showMessageDialog(null,"邵阳学院校园网","消息!",1);
}
else if(e.getSource()==jbArray[3])
{
JOptionPane.showMessageDialog(null,"没与网络连接,不能进行设置","消息!",1);
}
else if(e.getSource()==jcb1)
{
if(jcb1.getSelectedIndex()==0)
{
jlArray[0].setText("用户名");
jlArray[1].setText("密码");
jlArray[2].setText("语言");
jlArray[3].setText("网卡");
jbArray[0].setText("连接");
jbArray[1].setText("退出");
jbArray[2].setText("系统");
jbArray[3].setText("设置");
}
else if(jcb1.getSelectedIndex()==1)
{
jlArray[0].setText("User");
jlArray[1].setText("PassWord");
jlArray[2].setText("Language");
jlArray[3].setText("Adapter");
jbArray[0].setText("Connect");
jbArray[1].setText("Exit");
jbArray[2].setText("Message");
jbArray[3].setText("Configure");
}
}
}
public static void main(String[] args)
{
SchoolNet sn=new SchoolNet();
}
}
这道程序运行后,,,图形界面基本可以,刚学JAVA,许多方法不太会用,,,如何把“邵阳学院”“HU NAN SHAO YANG UNIVERSITY"的标签的全部背景设成红色了,还有一个问题就是,当我选择英文显示时,,,四个按钮并不能把英文全部显示出来,如何把英文字体字体设置小些,,让其全部显示出来,,,麻烦讲解
给button单独设置font方法2:
把登陆框的大小调大“如何把“邵阳学院”“HU NAN SHAO YANG UNIVERSITY"的标签的全部背景设成红色了”
是什么意思,我注意到你的代码已经把它设置成红色了
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;public class SchoolNet extends JFrame implements ActionListener {
private JPanel jp = new JPanel();
private JTextField jtf = new JTextField();
private JPasswordField jpf = new JPasswordField();
private JButton[] jbArray = { new JButton("连接"), new JButton("退出"),
new JButton("系统"), new JButton("设置") };
private JLabel[] jlArray = { new JLabel("用户名"), new JLabel("密码"),
new JLabel("语言"), new JLabel("网卡"), new JLabel("邵阳学院"),
new JLabel("HU NAN SHAO YANG UNIVERSITY"),
new JLabel("Supplicant 3.35-0618") };
private String str1[] = { "中文", "English" };
private JComboBox jcb1 = new JComboBox(str1);
private String str2[] = { "VIA Rhine Fast Ethernet Adapt" };
private JComboBox jcb2 = new JComboBox(str2); public SchoolNet() {
jp.setLayout(null);
// add new font for buttons
Font font1 = new Font("Courier",0,9);
for (int i = 0; i < 4; i++) {
jlArray[i].setBounds(20, 50 + i * 40, 80, 25);
jp.add(jlArray[i]);
jbArray[i].setBounds(10 + i * 80, 230, 70, 20);
// set font
jbArray[i].setFont(font1);
jp.add(jbArray[i]);
}
// release
font1 = null;
jtf.setBounds(80, 48, 200, 25);
jp.add(jtf);
jpf.setBounds(80, 88, 200, 25);
jp.add(jpf);
jcb1.setBounds(80, 128, 200, 25);
jp.add(jcb1);
jcb2.setBounds(80, 170, 200, 25);
jp.add(jcb2);
Font font = new Font("隶书", 0, 50);
jlArray[4].setFont(font);
jlArray[4].setBounds(60, 0, 210, 30);
jlArray[4].setOpaque(true);
jlArray[4].setBackground(Color.red);
jp.add(jlArray[4]);
jlArray[5].setBounds(70, 30, 185, 10);
jlArray[5].setOpaque(true);
jlArray[5].setBackground(Color.red);
jp.add(jlArray[5]);
jlArray[6].setBounds(200, 210, 130, 10);
jp.add(jlArray[6]);
jbArray[0].addActionListener(this);
jbArray[1].addActionListener(this);
jbArray[2].addActionListener(this);
jbArray[3].addActionListener(this);
jcb1.addActionListener(this);
this.add(jp);
this.setTitle("邵阳学院网络认证计费系统");
this.setBounds(300, 200, 340, 300);
this.setVisible(true);
} public void actionPerformed(ActionEvent e) {
if (e.getSource() == jbArray[0]) {
JOptionPane.showMessageDialog(null, "还没与数据库连接,不能连接", "消息!", 1);
} else if (e.getSource() == jbArray[1]) {
System.exit(0);
} else if (e.getSource() == jbArray[2]) {
JOptionPane.showMessageDialog(null, "邵阳学院校园网", "消息!", 1);
} else if (e.getSource() == jbArray[3]) {
JOptionPane.showMessageDialog(null, "没与网络连接,不能进行设置", "消息!", 1);
} else if (e.getSource() == jcb1) {
if (jcb1.getSelectedIndex() == 0) {
jlArray[0].setText("用户名");
jlArray[1].setText("密码");
jlArray[2].setText("语言");
jlArray[3].setText("网卡");
jbArray[0].setText("连接");
jbArray[1].setText("退出");
jbArray[2].setText("系统");
jbArray[3].setText("设置");
} else if (jcb1.getSelectedIndex() == 1) {
jlArray[0].setText("User");
jlArray[1].setText("PassWord");
jlArray[2].setText("Language");
jlArray[3].setText("Adapter");
jbArray[0].setText("Connect");
jbArray[1].setText("Exit");
jbArray[2].setText("Msg");
jbArray[3].setText("Config");
}
}
} public static void main(String[] args) {
new SchoolNet();
}
}
jlArray[5].setBounds(60, 30, 210, 10);
for(int i=0;i <4;i++)
{
jlArray[i].setBounds(20,50+i*40,840,25);
jp.add(jlArray[i]);
jbArray[i].setBounds(10+i*80,230,70,20);
jp.add(jbArray[i]);
jbArray[i].setMargin(new Insets(0,0,0,0));
}
给你改了这一点,英文全部显示出来了,你没有用布局管理器去设置整个frame。
for(int i=0;i <4;i++)
{
jlArray[i].setBounds(20,50+i*40,840,25);
jp.add(jlArray[i]);
jbArray[i].setBounds(10+i*80,230,70,20);
jp.add(jbArray[i]);
jbArray[i].setMargin(new Insets(0,0,0,0));
}