大小 setSize()
位置 setLocation()
颜色 setBackground()和setForeground()
位置 setLocation()
颜色 setBackground()和setForeground()
解决方案 »
- Java程序如何控制使只能启动一个程序(就是程序只能单开,不能像QQ那样可以同时挂好几个窗口)
- setCategoryMargin()
- 菜鸟提问:有关空指针
- 我是JAVA新手,我安装了JDK1.7系统变量也配置好了,但是为什么我在运行窗口里输入javac却显示'javac'不是内部或外部命令,也不是可运行的程序或批处理文件。
- 关于package和import的问题
- 请问..有什么办法让父类去调用子类的方法
- 谁能解释一下!
- 请问Web服务器与HTTP服务器有什么区别?
- JList的疑问
- 一个应用程序转换成applet程序的问题
- linux 下的java开发工具
- 大家好啊,十一假过的好吗?帮帮我吧,用java做个东西该.....
try{
UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
}catch(Exception e){
System.exit(1);
}这样你的按钮就会凸起来
这段代码要放在哪里?
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.plaf.metal.*;public class TestNetPaint
{
public static int count=100;
public static void main(String[] args)throws Exception
{
JFrame myframe=new MyFrame();
myframe.show();
}
}
class MyFrame extends JFrame
{
public MyFrame()
{
addWindowListener
(
new WindowAdapter()
{
public void windowClosing(WindowEvent e)
{
System.exit(0);
}
}
);
setSize(600,400);
Container contentPane=getContentPane();
MyPanel testPanel=new MyPanel();
JButton myButton=new JButton("test");
myButton.setFocusPainted(false);//取消聚焦框
myButton.setForeground(Color.pink);
myButton.setBackground(Color.blue);
testPanel.add(myButton);
contentPane.add(testPanel);
try{
UIManager.setLookAndFeel("com.sun.java.swing.plaf.windows.WindowsLookAndFeel");
SwingUtilities.updateComponentTreeUI(this);
}catch(Exception e){
System.exit(1);
}
}
}
class MyPanel extends JPanel
{
TestNetPaint netpaint=new TestNetPaint();
public MyPanel()
{
}
public void paint(Graphics g)
{
super.paint(g);
System.out.println("MyPanel is running");
}
} /*说明:1,在Swing里面我感觉控件的大小,位置无所谓的,只要你布局做的对,原始窗口
大小合适就好。
2,myButton.setFocusPainted(false);//取消 按钮上的test外还有个不知所云的框
3,UIManager.setLookAndFeel("com.sun.java.swing.plaf.windows.WindowsLookAndFeel");
SwingUtilities.updateComponentTreeUI(this); 这句不能少,否则没用
4, myButton.setForeground(Color.pink);
myButton.setBackground(Color.blue); 改变颜色
*/