我想创建一个带有标题' ,继承JFrame
类,这样我就不需要显式创建框架类的实例。怎么做?
以下是我的代码:
import javax.swing.*;
public class FrameByInheritance extends JFrame{//inheriting JFrame
FrameByInheritance(String s){
JButton b=new JButton("Submit");//create button
b.setBounds(130,100,100, 40);
add(b);//adding button on frame
setSize(400,500);
setLayout(null);
setVisible(true);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
public static void main(String[] args) {
new FrameByInheritance("Set me in frame Title bar");
//How to set title without craeting instance of parent class - JFrame
}
}
以上代码生成一个框架,但没有任何标题'在标题栏中。要设置标题,我必须创建JFrame
类的实例,并将标题作为参数传递给它的构造函数,如下所示:
JFrame f=new JFrame("Set me in frame Title bar");
但我不想显式创建JFrame
类的实例。那怎么办呢?
答案 0 :(得分:2)
答案 1 :(得分:0)
<main class="col-sm-9 offset-sm-3 col-md-10 offset-md-2">
<h1>Title</h1>
<div class="row">
<div class="col-md-12">
<div class="panel panel-default">
<div class="panel-heading">
<h3 class="panel-title">Title Info</h3>
<a href="#"><button type="button" class="btn btn-primary-panel-titles" aria-label="Left Align">Edit</button></a></div>
<div class="panel-body">
<div class="form-group">
<label class="control-label" for="year">Year</label>
<input name="site" disabled="disabled" class="form-control" type="text" value="2017/18 - 2017/18">
</div>
<strong>Payment Times: </strong> <div class="input-group col-md-2">
<input type="text" class="form-control" placeholder="Monthly" aria-describedby="basic-addon1" readonly="readonly">
</div>
<br></br>
<strong>Payment Type: </strong> Direct Debit
</div>
</div>
</div>
就像那样简单:)
或者只是JFrame#.setTitle("foo");
答案 2 :(得分:0)
尝试写作
setTitle("foo");
在构造函数的顶部