有一个包含一些组件的类,比如带有按钮等的jpanel。当我从这个类中的main方法运行这个类时,它工作正常。问题是,当我尝试从另一个类运行此类构造函数时,组件会令人失望。
function upd!(w,A,i,c)
rowval = A.rowval
nzval = A.nzval
@inbounds for j = nzrange(A,i)
w[rowval[j]] += c* nzval[j]
end
return w
end
@time for i=1:100000
upd!(w,A,i,1)
end
0.500323 seconds (99.49 k allocations: 1.518 MB)
当我尝试从我的另一个班级 CanvasFrame canvas = new CanvasFrame("Web Cam");
CanvasFrame capturecanvas =new CanvasFrame("Preview");
Canvas capturecanva = new Canvas();
JPanel controlPanel = new JPanel();
JLabel capturepanel=new JLabel();
JButton captureBtn;
JButton acceptBtn;
JButton retakeBtn;
String currentCapture;
JPanel panel = new JPanel();
int total_Faces;
public FaceDetector(int interruptionCommnand) throws IOException
{
captureInterrupt();
}
public FaceDetector() throws IOException, FrameGrabber.Exception
{
FrameGrabber grabber = new VideoInputFrameGrabber(0);
canvas.setDefaultCloseOperation(javax.swing.JFrame.EXIT_ON_CLOSE);
capturecanvas.setDefaultCloseOperation(javax.swing.JFrame.DISPOSE_ON_CLOSE);
canvas.setSize(800,600);
canvas.setLayout(new MigLayout("insets 0, gap 10" ));
Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
int locationX = (screenSize.width-240) / 2;
int locationY = (screenSize.height -550) / 2;
canvas.setBounds(locationX, locationY,840, 550);
panel.add(captureBtn = new JButton("Capture"), " w 100:100:100, h 40:40:40");
controlPanel.add(acceptBtn =new JButton("Accept"), "w 100:100:100, h 40:40:40");
controlPanel.add(retakeBtn=new JButton("Retake"), "w 100:100:100, h 40:40:40");
ActionListener RetakeActionListener = new RetakeActionListener();
retakeBtn.addActionListener(RetakeActionListener);
ActionListener AcceptActionListener = new AcceptActionListener();
acceptBtn.addActionListener(AcceptActionListener);
ActionListener CaptureActionListener = new CaptureActionListener();
captureBtn.addActionListener(CaptureActionListener);
canvas.add(panel,"south");
capturecanvas.setLayout(new MigLayout("wrap 3"));
capturecanvas.setVisible(false);
}
public static void main(String[] args) throws IOException, FrameGrabber.Exception
{
new FaceDetector();
}
运行它时,组件丢失了
更改后的代码:
new FaceDetector();
答案 0 :(得分:1)
尝试在Runnable
内运行。
Thread thread = new Thread(new Runnable(){
public void run() {
new FaceDetector();
}
});
thread.start();
修改强>
thread.start();
while(thread.isAlive()){};
try {
DatabaseConnectivity ndbc = new DatabaseConnectivity("select","");
ndbc.FrameShow();
} catch (SQLException ex) {
Logger.getLogger(RegisterService.class.getName()).log(Level.SEVERE, null, ex);
}