这样就行了 /**
* byq.java
* done by symbol windows风格
*/import javax.swing.*;
import java.awt.event.*;
import java.awt.*;public class byq extends JFrame
{
//定义
JButton Button1 = new JButton("开始编译"); //按钮
JTextArea textArea1 = new JTextArea ("在这里写代码",30,60);
JTextArea textArea2 = new JTextArea ("调试信息",30,60);
JLabel label1 = new JLabel("代码输入:"); //不是按钮,是静态文本
JLabel label2 = new JLabel("调试信息"); //不是按钮,是静态文本
Container pane = getContentPane();
JScrollPane scrollPane1 = new JScrollPane(textArea1);
JScrollPane scrollPane2 = new JScrollPane(textArea2); public byq() {
pane.setLayout( new BoxLayout( pane, BoxLayout.Y_AXIS ) );
textArea1.setLineWrap(true);
textArea2.setLineWrap(true); pane.add(label1);
pane.add(scrollPane1);
pane.add(label2);
pane.add(scrollPane2);
pane.add(Button1);
//颜色
pane.setBackground( Color.GREEN );
label1.setForeground( Color.RED );
label2.setForeground( Color.RED );
Button1.setForeground( Color.RED );
/* 为一般按钮添加动作监听器 */
Button1.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent ae)
{
JOptionPane.showMessageDialog(null,"开始编译","标题",JOptionPane.INFORMATION_MESSAGE);
System.exit(0);
}
});
setSize(800, 700);
System.out.println("this is my first window");
}
public static void main(String[] args)
{
try
{
UIManager.setLookAndFeel("com.sun.java.swing.plaf.windows.WindowsLookAndFeel");
}
catch(Exception e)
{
e.printStackTrace();
} byq win = new byq();
win.setVisible( true );
}}
* byq.java
* done by symbol windows风格
*/import javax.swing.*;
import java.awt.event.*;
import java.awt.*;public class byq extends JFrame
{
//定义
JButton Button1 = new JButton("开始编译"); //按钮
JTextArea textArea1 = new JTextArea ("在这里写代码",30,60);
JTextArea textArea2 = new JTextArea ("调试信息",30,60);
JLabel label1 = new JLabel("代码输入:"); //不是按钮,是静态文本
JLabel label2 = new JLabel("调试信息"); //不是按钮,是静态文本
Container pane = getContentPane();
JScrollPane scrollPane1 = new JScrollPane(textArea1);
JScrollPane scrollPane2 = new JScrollPane(textArea2); public byq() {
pane.setLayout( new BoxLayout( pane, BoxLayout.Y_AXIS ) );
textArea1.setLineWrap(true);
textArea2.setLineWrap(true); pane.add(label1);
pane.add(scrollPane1);
pane.add(label2);
pane.add(scrollPane2);
pane.add(Button1);
//颜色
pane.setBackground( Color.GREEN );
label1.setForeground( Color.RED );
label2.setForeground( Color.RED );
Button1.setForeground( Color.RED );
/* 为一般按钮添加动作监听器 */
Button1.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent ae)
{
JOptionPane.showMessageDialog(null,"开始编译","标题",JOptionPane.INFORMATION_MESSAGE);
System.exit(0);
}
});
setSize(800, 700);
System.out.println("this is my first window");
}
public static void main(String[] args)
{
try
{
UIManager.setLookAndFeel("com.sun.java.swing.plaf.windows.WindowsLookAndFeel");
}
catch(Exception e)
{
e.printStackTrace();
} byq win = new byq();
win.setVisible( true );
}}
解决方案 »
- 怎么用任务计划扫描java控制台程序是否运行
- J2SE工程的部署
- 请教如何在一个java程序中启动另一个java程序
- 使用Socket传压缩文件,收到的文件打不开
- 请问谁有JAVA核心技术1卷光盘里面的内容
- 新手关于事件派发线程问题,大家讨论^^
- 为什么关闭对话框必须点2下才能关闭呢?
- 输出流的小问题
- 由于JAVA没有指针,不知这个问题怎样解决??
- 实现我的诺言,散分,主要回答人如下:wjmmml(笑着悲伤),xmvigour(微电--有狼的气质 没狼的勇气 真郁闷),sharetop(燕赤霞),piggybank(
- 读取Excel的问题,请帮忙解决,多谢!
- 谁知道JBUIDER 9的注册码啊?
我实在找不出你的程序里面那里错了
所以我就重新自己写过一遍我有点怀疑是layout的问题
因为我主要也就是改layout的那个地方
不过我找不到问题在哪里
layout那样用好像也没有错。
JScrollPane scrollPane1 = new JScrollPane(textArea1);
JScrollPane scrollPane2 = new JScrollPane(textArea2);
getContentPane().add(textArea1);
getContentPane().add(textArea2);
你把textArea即加在滚动面板里,又加在了contentPane中,所以会出错。去掉下面两句就行了。
JScrollPane scrollPane2 = new JScrollPane(textArea2);
getContentPane().add(textArea1);
getContentPane().add(textArea2);
你把textArea即加在滚动面板里,又加在了contentPane中,所以会出错。去掉下面两句就行了。
正确,接粉!