我尝试用按钮创建网格表
package midterm
import java.awt.BorderLayout
import java.awt.Color
import java.awt.GridLayout
import javax.swing.JButton
import javax.swing.JPanel;
import scala.swing.Button
import scala.swing.MainFrame
import scala.swing.SimpleSwingApplication
object Main extends SimpleSwingApplication {
def top = new MainFrame {
title = "Hello, World!"
val panel = new JPanel()
var btn = Array.ofDim[JButton](8,8)
//contents =new JButton()
for(i<-0 to 7){
for(j<-0 to 7){
btn(i)(j)= new JButton("vsdf")
btn(i)(j).setBounds(i*80,j*80,80,80)
btn(i)(j).setBackground(Color.BLUE)
panel.add(btn(i)(j))
}
}
}
}
编译很好,但在输出中只有没有按钮的框架,仅此而已。请告诉我我的错误!