我正在为聊天程序编写GUI。我似乎无法让$('#calc').click(function(){
Math.GCD = function(numbers) {
for (var i = 1 ; i < numbers.length ; i++){
if(numbers[0]==""){
$.each($('.inputField'),function(){
if($(this).val()!=""){
numbers[0] = $(this).val();
return false;
}
});
}
if(numbers[0]!="" && numbers[i]!=""){
numbers[0] = twogcd(numbers[0], numbers[i])
}
}
return numbers[0];
if (numbers[i] === '' || numbers[i] === 0) {
numbers[0] = twogcd(numbers[0], numbers[i])
};
function twogcd(first, second) {
if (first < 0) first = -first;
if (second < 0) second = -second;
if (second > first) {var temp = first; first = second; second = temp;}
while (true) {
first %= second;
if (first == 0) return second;
second %= first;
if (second == 0) return first;
}
}
};
Math.LCM = function(first,second) {
return first * (second / this.GCD(first, second));
};
var first = $("#first").val();
var second = $("#second").val();
var third = $("#third").val();
var numbers = [first,second,third];
var GCDresult = Math.GCD(numbers);
alert(GCDresult);
});
水平和垂直填充框架,scroller
水平填充框架。这是它的外观:
messageInput
答案 0 :(得分:6)
让
scroller
水平和垂直填充框架,messageInput
水平填充框架。
您想要同时填写两个方向,请设置
c.fill = GridBagConstraints.BOTH; // not HORIZONTAL
下一部分是修正权重,它将告诉每个组件分配多少空间(相对):
scroller = new JScrollPane(content);
c.weightx = 0.5;
c.weighty = 1.0;
c.gridx = 0;
c.gridy = 0;
panel.add(scroller, c);
messageInput = new JTextField();
c.weightx = 0.5;
c.weighty = 0.0;
c.gridx = 0;
c.gridy = 1;
panel.add(messageInput, c);
weightx
应为非零值,以允许组件水平拉伸。 weighty
对于编辑器应该不为零,但对于文本字段不应该为零,这样它就不会占用额外的垂直空间(在这种情况下,您不需要设置c.fill = GridBagConstraints.HORIZONTAL
对于它)。